stdlib-js / google-summer-of-code

Google Summer of Code resources.
https://github.com/stdlib-js/stdlib
23 stars 5 forks source link

[RFC]: Functions for numerical integration and differentiation #54

Closed rajutkarsh07 closed 2 months ago

rajutkarsh07 commented 3 months ago

Full name

Utkarsh Raj

University status

Yes

University name

IIIT Jabalpur

University program

Computer Science and Engineering

Expected graduation

31-05-2025

Short biography

Hey there, I'm Utkarsh Raj, a third-year student pursuing a Bachelor's degree in Computer Science and Engineering at IIIT Jabalpur. I'm passionate about full-stack development, and I've got hands-on experience with a variety of technologies. During my internship, I dove into Fullstack development, honing my skills in JavaScript, TypeScript, Node.js, C, and C++. Beyond that, I've also dabbled in DevOps and Docker, expanding my toolkit to encompass all aspects of the development process.

My diverse skill set allows me to tackle problems from multiple angles, whether it's building web applications, crafting command-line interfaces, or diving deep into algorithmic challenges. I've poured my passion for development into numerous projects, each one showcasing my dedication to the craft.

In addition to practical experience, I've delved into theoretical foundations through coursework covering Data Structures and Algorithms, Probability and Statistics, Advanced Mathematics, and more. Mathematics holds a special place in my heart, which is why I've taken on project Functions for Numerical Integration and Differentiation to further explore its applications in programming

Timezone

India Standard Time

Contact details

email: utkarshraj1306@gmail.com, rajutkarsh2505@gmail.com , 21bcs229@iiitdmj.ac.in Phone number: +91 9693501629 Linkedin: https://www.linkedin.com/in/utkarshraj1306/ Github: https://github.com/rajutkarsh07

Platform

Linux

Editor

Visual Studio Code (VS Code) stands as my preferred code editor, because it seamlessly integrated with Ubuntu's ecosystem, offering extensive features and plugins for efficient software development. Its intuitive interface, robust debugging capabilities, and built-in support for various programming languages, particularly JavaScript, C and C++ streamline my workflow, ensuring high-quality code and efficient collaboration via Git integration. Operating within Ubuntu, VS Code serves as a versatile tool for web development, allowing seamless navigation between files, folders, and projects, while its mature environment and extensive extension library enhance developer experience. Whether for work or personal projects, VS Code remains my go-to editor, providing everything needed in one place for productive coding and version control.

Programming experience

I've been passionate about programming since high school, and over the years, I've honed my skills in a variety of languages including JavaScript, C, C++, TypeScript, Node.js, and Python. My journey includes reaching a maximum rating of 1536 on Codeforces and successfully solving over 1000 problems across platforms like Codeforces, LeetCode, and GeeksforGeeks. I've actively participated in numerous hackathons, bringing my problem-solving abilities to the forefront. Moreover, I've contributed as a full-stack developer at e-Pocket, Australia, gaining practical experience in developing real-world applications. Additionally, I've been selected as a contributor in LFX Mentorship, further solidifying my commitment to open-source contributions. I have made several full-stack projects and CLI projects also

I also have a good performance in hackathons

I've showcased my proficiency in working with web APIs, real-time data within a JavaScript environment. These experiences have equipped me with the skills necessary to excel in projects like this.

JavaScript experience

Over the past three years, I've delved deep into JavaScript, acquiring a comprehensive understanding of its syntax, features, and underlying mechanics. I've dedicated myself to mastering its intricacies, from comprehending its event loop mechanisms to seamlessly navigating between synchronous and asynchronous operations. This journey has seen me engage in a diverse range of projects, from dynamic web development ventures to crafting robust command-line interfaces using Node.js.

One of the standout features of JavaScript, in my opinion, is its asynchronous programming paradigm, exemplified by the elegant syntax of async/await. This powerful combination enables developers to craft code that is not only clean and concise but also highly efficient, effectively managing asynchronous operations with ease.

In addition to mastering the fundamentals of JavaScript, I've extensively explored various libraries and frameworks that enrich its ecosystem. My repertoire includes React, Angular, Vue, Node.js, and Express, among others. Despite the flexibility offered by JavaScript's dynamic nature, I've encountered challenges in maintaining code organization and ensuring seamless functionality, especially in large-scale projects. However, I remain steadfast in my pursuit of innovative solutions, continuously pushing the boundaries of what can be achieved with JavaScript.

Node.js experience

My experience with Node.js spans across a wide spectrum of projects, showcasing my proficiency in backend development and CLI application creation. I've developed numerous backend APIs using Node.js, employing its powerful features to build robust and scalable solutions. Moreover, I've leveraged Node.js in crafting CLI applications, harnessing its versatility to deliver efficient command-line tools.

In addition to these endeavors, I've spearheaded the development of several full-stack web applications, where Node.js served as the backbone of the backend infrastructure. My role as a full-stack developer provided me with invaluable opportunities to further hone my skills in utilizing Node.js to create seamless and feature-rich web experiences.

C/Fortran experience

I began my journey with C and C++ during my first year of college when these languages were introduced as part of my coursework. I learned data structures and algorithms using C and C++, and I also engaged in competitive programming in C++, mastering its syntax and leveraging its features to solve algorithmic challenges effectively. Additionally, my academic pursuits led me to explore advanced numerical mathematics, where I undertook assignments involving the implementation of mathematical algorithms.

While I haven't used Fortran as extensively as JavaScript or C/C++, I do understand its importance in scientific computing. Fortran's specialized features for handling numerical operations and arrays make it ideal for tasks such as linear algebra and simulations. It serves as a valuable tool in the field of computational mathematics. but I am assured of my capacity to swiftly adapt and grasp new languages and technologies, drawing upon my existing programming knowledge and experience.

Interest in stdlib

The Stdlib library seamlessly merges my passion for mathematics with my expertise in web development, offering a comprehensive toolkit within the Node.js ecosystem. Its extensive range of utility functions and modules, spanning mathematical computations to file system operations, empowers developers of varying skill levels to efficiently address diverse project requirements. Stdlib's commitment to excellence, performance optimization, and adherence to industry standards fosters trust and widespread adoption within the Node.js community. Particularly noteworthy is Stdlib's support for advanced numerical computations, including robust random number generation capabilities, which fill a significant gap in JavaScript's native capabilities. This comprehensive support not only enhances JavaScript's utility for web development but also positions it as a practical toolkit for scientific and technical computing tasks, fostering a vibrant community around scientific computing in JavaScript.

Version control

Yes

Contributions to stdlib

So far in stdlib I have merged 3 pull requests and have 3 open pull request and 2 closed pull request:

Merged PRs:

Open PRs;

Closed PRs:

Goals

My goal with this project is to implement Functions for numerical integration, ODE and differentiation, providing developers like myself with robust tools for solving mathematical and scientific problems. Implement functions for numerical integration and differentiation using the composite Simpson's rule and the composite trapezoidal rule. Implement mathematical functions that are not currently available in the stdlib-js and will be required in implemention of these functions,

Implementation

Integration Functions

Composite Simpson's Rule Integration

This module provides a function to integrate a given array y(x) using samples along the given axis and the composite Simpson's rule.

reference scipy/simpson

Usage

Function Signature

integrate_simpson(y, (x = None), (dx = 1.0), (axis = -1), (even = None));

Simpson

/**
 * Integrate `y(x)` using samples along the given axis and the composite Simpson's rule.
 *
 * @param {Array<number>} y - Array to be integrated.
 * @param {Array<number> | null} [x=null] - If given, the points at which `y` is sampled.
 * @param {number} [dx=1.0] - Spacing of integration points along the axis of `x`. Only used when `x` is null. Default is 1.0.
 * @param {number} [axis=-1] - Axis along which to integrate. Default is the last axis.
 * @param {string | null} [even=null] - Determines how to handle integration when there are an even number of samples. Options are 'simpson', 'avg', 'first', 'last', or null. Default is null.
 * @returns {number} - The estimated integral computed with the composite Simpson's rule.
 * @throws {Error} - If the shapes of `x` and `y` do not align.
 */
function simpson(y, x = null, dx = 1.0, axis = -1, even = null) {
  // Function implementation
}

Trapezoid

/**
 * Integrate along the given axis using the composite trapezoidal rule.
 *
 * @param {Array<number>} y - Input array to integrate.
 * @param {Array<number> | null} [x=null] - The sample points corresponding to the `y` values. If `x` is null, the sample points are assumed to be evenly spaced `dx` apart. The default is null.
 * @param {number} [dx=1.0] - The spacing between sample points when `x` is null. The default is 1.0.
 * @param {number} [axis=-1] - The axis along which to integrate.
 * @returns {number | Array<number>} - Definite integral of `y` as approximated along a single axis by the trapezoidal rule. If `y` is a 1-dimensional array, then the result is a float. If `n` is greater than 1, then the result is an `n`-1 dimensional array.
 */
function trapezoid(y, x = null, dx = 1.0, axis = -1) {
  // Function implementation
}

Explanation

The integrate_simpson function takes an array y(x) and optionally, an array x representing the points at which y is sampled. If x is not provided, the function assumes a uniform spacing of dx along the x-axis. The integration is performed along the specified axis, with the default being the last axis. The parameter even determines how to handle integration when there are an even number of samples. Finally, the function returns the estimated integral computed using the composite Simpson's rule.

Required functions

Differentiation

Reference: scipy/misc/_common.py#L84

Parameters

Returns

Exceptions

Example

const derivative = require('derivative'); // after successfull implementation of derivatives
function f(x) {
  return Math.pow(x, 3) + Math.pow(x, 2);
}

// Compute the derivative of f at x = 1.0
let result = derivative(f, 1.0);

console.log(result);

ODE (Ordinary Differential Equations)

reference: scipy/integrate/_ode.py#L103

The ODE package contains several solvers for solving Ordinary Differential Equations (ODEs), including:

Reference

Implementation Plan

To implement the ode class:

  1. Define the right-hand side function f(t, y, *f_args) representing the system of ODEs to solve.
  2. Optionally, define the Jacobian function jac(t, y, *jac_args) if required by the solver.
  3. Initialize an instance of the ode class, passing the f and jac functions (if applicable).
  4. Set additional parameters for the integrator using setIntegrator method.
  5. Set initial conditions for the ODE system using setInitialValue method.
  6. Integrate the ODE system over the desired time span using integrate method.

Example Usage

const { ode } = require('ode'); // after successful implementation of ode

const y0 = [1.0i, 2.0];
const t0 = 0;

function f(t, y, arg1) {
    return [1i * arg1 * y[0] + y[1], -arg1 * y[1] ** 2];
}

function jac(t, y, arg1) {
    return [[1i * arg1, 1], [0, -arg1 * 2 * y[1]]];
}

const r = ode(f, jac).setIntegrator('zvode', { method: 'bdf' });
r.setInitialValue(y0, t0).setParams({ f: [2.0], jac: [2.0] });

const t1 = 10;
const dt = 1;
while (r.successful() && r.t < t1) {
    console.log(r.t + dt, r.integrate(r.t + dt));
}

Why this project?

As someone deeply passionate about mathematical concepts and adept at crafting efficient algorithms, the goal of this project speaks directly to my interests. I am excited about the prospect of merging my skills and passions to contribute to the advancement of Stdlib. Introducing functions for numerical integration or differentiation holds immense potential for enhancing Stdlib's capabilities, making it an essential resource for developers tackling intricate mathematical computations. Leveraging my enthusiasm for mathematical concepts and algorithm optimization, I am eager to embark on this journey. Whether by adapting existing open-source libraries or creating implementations from scratch, I am committed to making meaningful contributions to the JavaScript ecosystem. This project perfectly aligns with my expertise and aspirations, driving my enthusiasm to play a pivotal role in its success.

Qualifications

Professional Experience in JavaScript:

Strong Competence in Algorithms and Data Structures:

Technical Proficiency in C++:

Academic Pursuits in Computer Science:

Exceptional Academic Performance:

Mathematical Proficiency:

Prior art

During my research for this project, I extensively explored various resources and repositories to gather insights and understand existing implementations. Specifically, I reviewed the GitHub repository for scijs/ode45-cash-karp to gain understanding of numerical methods for solving ordinary differential equations. Additionally, I thoroughly examined SciPy, a widely-used scientific computing library, to understand its implementation of numerical integration and differentiation methods.

These resources provided valuable insights and served as a foundation for my project implementation.```

Commitment

1 May - 26 May -> Bonding Period 27 May - 7 July -> 40 hours/week ( 40 6 ) 8 July - 17 August -> 21 hours/week ( 21 6 ) Total = 240 + 126 = 346 hours Apart from this, I don't have any other commitments during the coding period.

Schedule

Assuming a 12 week schedule,

Notes:

Related issues

Checklist

rajutkarsh07 commented 3 months ago

@kgryte @Planeshifter @rreusser @Pranavchiku @czgdp1807 Please give suggestions for improvement

kgryte commented 3 months ago

@rajutkarsh07 Thank you for sharing a draft of your proposal. A few comments:

  1. While all these APIs would make great additions, I am curious about their feasibility. Namely, do we have all the prerequisite functionality needed to implement these APIs? If we are missing necessary functionality, that could significantly affect the timeline you propose. As such, I strongly recommend doing some R&D, such as by exploring the source code of SciPy, to better understand implementation dependencies, and then cross-referencing back to stdlib to see what's available and what's missing.
  2. Your proposal doesn't provide any concrete API proposals. I suggest providing some example signatures and a discussion of input argument types and necessary options. Will these work on strided arrays? ndarrays? regular arrays? Will they need to support options, such as tolerances, methods, or something else? Again, SciPy may provide a good reference here.
rajutkarsh07 commented 3 months ago

Thank you, @kgryte, for your valuable feedback and insights regarding the proposed project. I've carefully considered your suggestions, and based on further research, I've decided to focus solely on implementing the functions for differentiation, Simpson's rule, and ordinary differential equations (ODEs) during this summer.

I've incorporated the implementation details for these specific functions, along with comprehensive plans, examples, and usages.