Giter Club home page Giter Club logo

scidart's Introduction

Scidart logo

SciDart is an experimental cross-platform scientific library for Dart.

🏹 Goals

The main goal of SciDart is run where Dart can run, in other words, run on Flutter, Dart CLI, Dart web, etc.

πŸƒ Motivation

Some time ago I tried make a guitar tuner (frequency estimator) with Flutter, and I faced with the problem: Dart didn't have a unified scientific library. So, I tried implement something to help me and the community with this problem.

🧭 PUB link

Link to the Pub repository: https://pub.dev/packages/scidart

πŸ”Œ Installation

You can follow instruction in the Pub website: https://pub.dev/packages/scidart#-installing-tab-

βš’ Examples

The examples can be found in the project web site.

πŸ›£ Project milestones

All the project status will be shared and updated in the Projects section of Github.

πŸ™Œ How to contribute

I recommend check the Projects section and choose a task or choose and solve a problem with SciDart and implement the missing parts and read the file CONTRIBUTING.md.

The reference values for all functions came from with SciPy. The contributions need use SciPy as reference too.

Every contribution need to have tests, documentation and examples, otherwise, the pull request will be blocked.

β˜• Supporters

Scidart is an open source project that runs on donations to pay the bills e.g. our domain name. If you want to support Scidart, you can β˜• buy a coffee here.

⚠ License

Copyright (c) 2019-present Angelo Polotto and Contributors. Scidart is free and open-source software licensed under the Apache-2.0 License. The official logo was created by Juliano Polotto and distributed under Creative Commons license (CC BY-SA 4.0 International).

scidart's People

Contributors

andrewdevetry avatar hugobrancowb avatar miguelfs avatar mishkov avatar myconsciousness avatar polotto avatar polotto-picpay avatar pronicx avatar saroad2 avatar srawlins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

scidart's Issues

Hamming window not symmetrical.

I used the hamming function with sym=true. but it just return the list which starts from zero and goes up to 1 but not coming down.

The name of arange()

At the moment we have the arange() method with a name from python repo, if I am right. The problem is that the name of arange() method does not match Dart name conventions because it contains some abbreviation which is bad practice. The name as described here means "array range" and should have other name. It can be createArrayRange, buildArrayRange, or less readable arrayRange.

P. S.
Maybe I am paranoiac or crazy clean coder but I would like to get your opinion about that.

The mode implementation is wrong

Page URL

https://pub.dev/documentation/scidart/latest/numdart/mode.html

The implementation for finding mode does not return mode correctly mainly because mode is not always a single number like in [5,0,6,8,10,8,10] the mode is 10 and 8 so the mode function should return a list of double.
Expected fix

I think this implementation is better than the one provided only problem with it is it will return the uniqueDataPoints if all of the doubles provided occur the same amount of times like in [1,1,2,2,3,3,4,4,5,5,6,6,7,7]


List<double> mode(List<double> dataPoints) {
    final List<double> modes = [];
    final uniqueDataPoints = dataPoints.toSet();

    int maxFrequency = 0;

    for (var dataPoint in uniqueDataPoints) {
      var frequency =
          dataPoints.where((element) => element == dataPoint).length;
      if (frequency > maxFrequency) {
        maxFrequency = frequency;
        modes.clear();
        modes.add(dataPoint);
      } else if (frequency == maxFrequency) {
        modes.add(dataPoint);
      }
    }

    return modes;
  }

Finding root of a function

Description

There should be a way to caclulate the root of a function using scidart.
That function should generaly be from n dimentional space to m dimentional space.

Suggested API

Taking inspiration from scipy, the API should look like:

OptimizeResult root(   // calculating root for multidimentional functions
    Array Function(Array) func, // function to find root of
    Array x0,  // initial guess for the root
    {
        RootAlgorithm method = RootAlgorithm.hybr, // optiomization algorithm
        Array2d Function(Array)? jac, // possible jacobian method
        double tolerance = 1e-5,  // chosen tolerance
    }
) {
    ...
}

OptimizeResult rootScalar(   // calculating root for scalar functions
    double Function(double) func, // function to find root of
    double x0,  // initial guess for the root
    {
        RootAlgorithm method = RootAlgorithm.hybr, // optiomization algorithm
        double Function(double)? jac, // possible jacobian method
        double tolerance = 1e-5,  // chosen tolerance
    }
) {
    ...
}

Where OptimizeResult is a class from the following form:

class OptimizeResult {
    Array result;  // the result of the optiomization
    bool success;  // is the optimzation was successful
    int iterations; // number of iterations until stopping
    String message;  // explanatory message for the reason of termination
    OptimizeResult({
        required this.result, 
        required this.success, 
        required this.iterations,
        required this.message,  
    });
}

And the RootAlgorithm enum should look like:

enum RootAlgorithm {
    hybr,
    lm,
    broyden,
    anderson,
    linearmixing,
    diagbroyden,
    excitingmixing,
    krylov,
    dfSane,
}

Possible Roadmap

In my opinion, the best option to start with is the implimentation of the RootAlgorithm.brodyden method.
It is quite simple, relies havily on Newton–Raphson method, and is well documented.

After that, we can continue to implement the other methods.

Summary

Finding functions' roots is a very important ability in order to make scidart a legitimate alternative for other scientific libraries.

Please let know if you approve my approach and I'll go ahead and implement it.

SVD calculation wrong answer

I test the result of SVD class with Matlab and Python. The only problem that existed was that the output value was equal to other software, but the positivity and negativity of the numbers were incorrect. For example, the result of calculations in other software was +1.5 at specific indices of the output matrix, but in your method, it was -1.5, and vice versa.

Infinite loop, memory exhausted with PolyFit(x, y, degree)

Hello,

I've noticed an infinite loop leading to my company app using 100% of available memory for one of our user.
This error is caused by PolyFit(Array x, Array y, int degree) and generate no error and no log.
It is reproductible using these values:

Array y = Array([7614, 7614, 7614, 7980, 7980, 7980, 7980]);
Array y = Array([1, 4, 20, 25, 25, 20, 4]);
PolyFit polynomial = PolyFit(x, y, 5); // Infinite loop

I'm not good at doing maths and not sure if it is possible to compute a polynomial using these values, thus these kind of unhandled case leading to an infinite loop should not occur.
I'm also not sure on how to fix it, however a security may be added to the while (true) {... line 78 of the file.

I would appreciate any answer,
Thank you, you are doing an amazing job with scidart !

enhancement: add cross-correlation

[x] I've read the Code of Conduct.


Hi. I miss a cross-correlation functionality in the library.

The library has a convolution implementation, both by shifting the signal and by using a FFT implementation.

The cross-correlation could be done by adapting the convolution case, like:

import 'package:scidart/numdart.dart';
import 'package:scidart/scidart.dart';

List<double> cross_correlation(List<double> y, List<double> x, {fast = false}) {
  return convolution(Array(x), Array(y.reversed.toList()), fast: fast);
  }

  test('test correlation array', () {
    expect(cross_correlation([1,0,0,0,0], [0,0,0,0,1]), [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]);
    expect(cross_correlation([0,0,1,0,0], [0,0,1,0,0]), [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0]);
    expect(cross_correlation([0,0,0,0,1], [1,0,0,0,0]), [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]);
  });

Polynomial regression

Is it possible to have multivariate polynomial regression with N features as input?
Like
const x = [[f1,f2,f3,f4,f5], [f1,f2,f3,f4,f5], [f1,f2,f3,f4,f5],[f1,f2,f3,f4,f5], [f1,f2,f3,f4,f5], ......];

Where [f1,f2,f3,f4,f5] is a 5D feature.
Output is 2D point.
const y = [[0, 1], [1, 6], [4, 11], [0, 2], [0, 5], [3, 7], [12, 15]];

arrayComplexConcat is slow

Hi, guys. Thanks for this awesome library :)

The following code seems to run slowly:

import 'package:scidart/numdart.dart';
import 'package:scidart/scidart.dart';
...
  test('cross correlate', () async {
    final sr = 48000;
    final x = ones(sr * 5);

    final s = Stopwatch();
    s.start();
    final y = correlate(x, x, fast: true);
    s.stop();
    print(s.elapsedMilliseconds / 1000);
  });

By adding breakpoints, I've verified the problem is in the the zero padding from arrayComplexPadStart. It calls the function below internally:

ArrayComplex arrayComplexConcat(ArrayComplex a, ArrayComplex b) {
  var c = ArrayComplex.empty();
  for (var i = 0; i < a.length; i++) {
    c.add(a[i]);
  }
  for (var i = 0; i < b.length; i++) {
    c.add(b[i]);
  }
  return c;
}

looping an .add function seems to run slowly. I wonder if there's an optimized way to concat both arrays.


  test('complex concat', () async {
    final sr = 8000;
    final x = arrayToComplexArray(ones(sr * 5));
    final s = Stopwatch();
    s.start();
    final y = arrayComplexConcat(x, x);
    print('seconds: ' + (s.elapsedMilliseconds / 1000).toString());
  });

prompts: seconds: 8.098

Unexpected result from fft on 256 array

Hi, I have been struggling to get expected results using an input array of 256 in length when compared to the equivalent in scipy. It seems to work fine when using a smaller input, e.g. length 8.
I might be missing something.

Here's the python script I have used to generate the expected results:
`import numpy as np
import scipy as sc

arr = np.array([
0.89968999,
0.89968999,
0.89968999,
0.89968999,
0.89968999,
0.61548992,
0.89968999,
0.61548992,
0.61548992,
0.33128984,
0.33128984,
0.047089768,
0.047089768,
0.33128984,
0.33128984,
0.33128984,
0.61548992,
0.89968999,
1.1838901,
0.61548992,
0.047089768,
-0.23711031,
0.047089768,
0.89968999,
0.33128984,
-1.3739106,
-1.3739106,
-1.3739106,
-0.23711031,
0.047089768,
0.61548992,
0.61548992,
-0.52131038,
-1.6581107,
-2.2265108,
-1.9423108,
-0.80551046,
-0.52131038,
0.33128984,
0.33128984,
0.61548992,
0.33128984,
0.047089768,
-0.23711031,
-0.23711031,
-0.52131038,
-0.80551046,
-0.80551046,
-0.52131038,
-0.52131038,
-0.52131038,
-0.23711031,
-0.52131038,
-0.23711031,
-0.23711031,
-0.23711031,
-0.52131038,
-0.52131038,
-0.52131038,
-0.52131038,
0.047089768,
0.33128984,
0.89968999,
0.33128984,
0.89968999,
0.89968999,
-0.23711031,
-0.80551046,
-0.80551046,
0.047089768,
1.1838901,
1.4680901,
0.89968999,
-0.52131038,
-0.80551046,
-0.52131038,
-0.23711031,
0.047089768,
-0.23711031,
-0.52131038,
-0.52131038,
0.047089768,
0.047089768,
0.33128984,
0.047089768,
0.047089768,
0.047089768,
0.047089768,
0.047089768,
0.047089768,
-0.23711031,
-0.23711031,
0.047089768,
0.047089768,
0.33128984,
0.047089768,
-0.23711031,
-0.23711031,
0.047089768,
0.89968999,
0.89968999,
1.1838901,
0.61548992,
-0.23711031,
0.047089768,
-0.23711031,
-0.23711031,
-0.23711031,
-0.23711031,
-0.52131038,
-0.52131038,
-1.9423108,
-2.2265108,
-2.5107109,
-1.6581107,
-0.52131038,
0.33128984,
1.4680901,
1.1838901,
0.61548992,
-0.23711031,
-0.52131038,
-0.52131038,
-0.52131038,
-0.52131038,
0.047089768,
0.047089768,
0.047089768,
-0.23711031,
-0.52131038,
-0.80551046,
-0.80551046,
-0.23711031,
0.047089768,
0.047089768,
-0.23711031,
-0.23711031,
-0.23711031,
-0.23711031,
0.047089768,
0.33128984,
0.33128984,
1.7522902,
0.89968999,
0.33128984,
0.33128984,
-0.80551046,
-0.80551046,
-1.0897105,
-0.23711031,
0.61548992,
0.61548992,
-0.23711031,
-0.80551046,
-1.0897105,
-0.80551046,
-0.23711031,
0.047089768,
0.047089768,
0.047089768,
-0.23711031,
0.33128984,
0.61548992,
0.61548992,
0.61548992,
0.33128984,
0.33128984,
0.33128984,
0.047089768,
0.047089768,
-0.23711031,
-0.23711031,
0.047089768,
0.047089768,
0.047089768,
0.047089768,
-0.23711031,
0.047089768,
0.33128984,
0.61548992,
0.61548992,
0.89968999,
0.33128984,
-0.52131038,
0.33128984,
-0.23711031,
-0.23711031,
-0.23711031,
-0.23711031,
-0.23711031,
-0.52131038,
-1.3739106,
-2.2265108,
-2.794911,
-2.2265108,
-0.80551046,
0.89968999,
1.4680901,
1.1838901,
0.33128984,
-0.23711031,
-0.23711031,
-0.80551046,
-1.0897105,
-0.52131038,
0.047089768,
0.61548992,
0.61548992,
0.33128984,
0.047089768,
-0.23711031,
-0.23711031,
-0.23711031,
-0.23711031,
0.047089768,
0.33128984,
0.89968999,
0.89968999,
1.1838901,
0.89968999,
-0.23711031,
0.047089768,
2.0364903,
2.3206904,
0.61548992,
-0.52131038,
-1.0897105,
-0.52131038,
0.33128984,
0.61548992,
-0.23711031,
-0.80551046,
-1.6581107,
-1.9423108,
-1.0897105,
-0.52131038,
-0.23711031,
-0.52131038,
-0.23711031,
0.047089768,
0.33128984,
0.89968999,
0.61548992,
0.89968999,
0.61548992,
0.61548992,
0.61548992,
0.61548992,
0.61548992,
0.33128984,
0.33128984,
0.33128984,
0.33128984,
0.047089768,
0.33128984,
0.33128984
]);

v1 = sc.fft(arr)
for p in v1:
print("Complex(real: {0}, imaginary: {1}),".format(p.real,p.imag))`

I have been trying to test by modifying the 'fft of a signal' test in: test/scidart/fftpack/fft/fft_test.dart.
The first result at position 0 matches, but from position 1 on there is a mismatch.

Error in test from position 1:
Expected: <17.68839497>
Actual: <11.41557497>

Thanks.

Benchmarks for common functions.

Hi

I would like to see benchmarks for commonly needed fast math, like FFTs and such.

I would also consider bundling a BLAS library for the main platforms through flutter/ ffi

PolyFit is not working as reqired

I was performing PolyFit(x, y, 3) but the equation which I got after this is of order 8. My x and y array are of length 9. Please help me.

rifft is giving diffrent values from np.fft.irfft

In dart:
var X = ArrayComplex([
Complex(real: 31.108143074615633, imaginary: -4.037293439117874),
Complex(real: -22.413467454124664, imaginary: 0.5718233105591632),
Complex(real: 11.988831263334843, imaginary: 0.04538347618383224),
]);

var mockPrint = ff.rifft(X);
print(mockPrint);

output:
Array([1.0876611583738058, 4.608367320860204, 22.003620671218734, 5.167541335271735])

In python:
mockPrint = np.fft.irfft([31.108143074615633-4.037293439117874j,-22.413467454124664+0.5718233105591632j, 11.988831263334843+0.04538347618383224j])

print(mockPrint[0]) 
print(mockPrint[1]) 
print(mockPrint[2]) 
print(mockPrint[3]) 

output:
-0.4324901425747125
4.493916297540616
21.98097731154995
5.065739608099778

for large chunk of data ouput vary the most

Normal Distributions

Hello,

Any plans to add scipy.stats distributions to this package?

Normals, skewed normals, truncated normals etc

Thanks

Array2d.fromArray is not deep copying the arrays in the list of arrays

Example:
var Mcat = nd.Array2d([ nd.Array([0.8951, 0.2664, -0.1614]), nd.Array([-0.7502, 1.7135, 0.0367]), nd.Array([0.0389, -0.0685, 1.0296]), ]); var mcatCopy = Mcat.copy(); mcatCopy[0][0] = 0.5;

Now Mcat[0][0] is also equal to 0.5

The problem seems to be that
Array2d.fromArray(Array2d list) { // deep copy of the parameter l = list.map((element) => element).toList(); }
just shallow copies the arrays stored in the list of arrays for Array2d.

Fix:
Array2d.fromArray(Array2d list) { // deep copy of the parameter l = list.map((element) => Array.fromArray(element)).toList(); }

scidart not building

just tried to install it on a plain new flutter app and got this output:

Compiler message:                                                       
../flutter/.pub-cache/hosted/pub.dartlang.org/scidart-0.0.1-dev.5/lib/src/numdart/arrays_base/array.dart:141:23: Error: The method '[]' isn't defined for the class 'Object'.
 - 'Object' is from 'dart:core'.                                        
Try correcting the name to the name of an existing method, or defining a method named '[]'.
      if (this[i] != b[i]) {                                            
                      ^^                                                
../flutter/.pub-cache/hosted/pub.dartlang.org/scidart-0.0.1-dev.5/lib/src/numdart/arrays_base/array2d.dart:204:23: Error: The method '[]' isn't defined for the class 'Object'.
 - 'Object' is from 'dart:core'.                                        
Try correcting the name to the name of an existing method, or defining a method named '[]'.
      if (this[i] != b[i]) {                                            
                      ^^                                                
../flutter/.pub-cache/hosted/pub.dartlang.org/scidart-0.0.1-dev.5/lib/src/numdart/arrays_base/array_complex.dart:105:23: Error: The method '[]' isn't defined for the class 'Object'.
 - 'Object' is from 'dart:core'.                                        
Try correcting the name to the name of an existing method, or defining a method named '[]'.
      if (this[i] != b[i]) {                                            
                      ^^                                                
Compiler failed on /home/davidhin/Projects/AppDev/scidarttest/lib/main.dart
                                                                        
FAILURE: Build failed with an exception.                                
                                                                        
* Where:                                                                
Script '/home/davidhin/Projects/AppDev/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 765
                                                                        
* What went wrong:                                                      
Execution failed for task ':app:compileFlutterBuildDebugArm'.           
> Process 'command '/home/davidhin/Projects/AppDev/flutter/bin/flutter'' finished with non-zero exit value 1
                                                                        
* Try:                                                                  
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
                                                                        
* Get more help at https://help.gradle.org                              
                                                                        
BUILD FAILED in 10s                                                     
Running Gradle task 'assembleDebug'...                                  
Running Gradle task 'assembleDebug'... Done                        10.8s
Gradle task assembleDebug failed with exit code 1

I'm still new to flutter, is there something I did wrong? I put scidart: ^0.0.1-dev.5 in the dependencies and import 'package:scidart/scidart.dart'; in the default lib/main.dart file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.