Coder Social home page Coder Social logo

numphp's People

Contributors

landrok 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

Watchers

 avatar  avatar  avatar  avatar  avatar

numphp's Issues

Convert kmeans from numpy to numphp

Hi, i tried to port a kmeans algorithm from python to php using your numpy like library.
Somehow I do not fully understand how to operate matrices correctly using your lib.
Are the Parameters axis, keepdims of sum compatible to numpy?
Can you help me get this code running with your lib? I put the Python version into comments.

function kmeans(NdArray $X, $K, $maxIter = 20, $beta = 1.0){
    list($N, $D) = $X->shape;

    $R          = np::zeros($N, $K); // Responsibility Matrix
    $exponents  = np::nulls($N, $K); // Exponents

    // initialize M with random values of X
    $M = randomize($X, $K, $N);


    for($i=0; $i< $maxIter; $i++){
        // step 1: determine assignments / resposibilities
        for($k=0; $k < $K; $k++){
            for($n=0; $n < $N; $n++){

                // Python:  exponents[n,k] = np.exp(-beta*d(M[k], X[n]))
                $exponents[$n][$k] = np::exp(-$beta * distance($M[$k], $X[$n]));

                // Python: R = exponents / exponents.sum(axis=1, keepdims=True)
                $R = $exponents->divide($exponents->sum());
            }
        }

        // step 2: recalculate means
        for($k=0; $k < $K; $k++){

            // Python: M = R.T.dot(X) / R.sum(axis=0, keepdims=True).T
            $M[$k] = np::transpose($R)->dot($X)->divide(np::transpose($R->sum()));
        }
    }

    echo $M; die;
}

function randomize(NdArray $X, $K, $N)
{
    $randomMeans = [];
    for($k=0;$k < $K; $k++){
        $randomMeans[$k] = $X[rand(0, $N-1)]->data;
    }
    return np::ar($randomMeans);
}

Working on SciPhp\Random class?

Hello again,
I Was doing my exercise using this great library and I needed random class. The class is missing and I've written some function.
I Want to know if you're working on this feature, if not yet, I can suggest my tiny functions( they use php native rand function )
-random::rand()
-random::randn()
-random::randint()
-random::randrange()
-random::choice()
-random::normal()
-random::shuffle()
(I used numpy as reference, so these method are numpy like)
Due to some difficulties, I can make a commit on github now.
I'm adapting my random class to the lib now. After finishing ( to adapt it) I can send you a link if possible to check them.
Bon weekend ร  vous!

What does filterRange() do?

Hi,
I 'm trying to implant a RNN class in php originally written in python.
I've tried to implant some basic np.random class functions but I have A Problem when I Try use the library.
i don't know which method is causing this, here is exception message:

Fatal error: Uncaught InvalidArgumentException: Expected a value between 0 and 0. Got: 1 in /home/htdocs/ai/numphp/webmozart/assert/src/Assert.php:2042 Stack trace:
#0 /home/htdocs/ai/numphp/webmozart/assert/src/Assert.php(922): Webmozart\Assert\Assert::reportInvalidArgument
('Expected a valu...') #1 /home/htdocs/ai/numphp/sciphp/numphp/src/SciPhp/NdArray/IndexTrait.php
(231): Webmozart\Assert\Assert::range(1, 0, 0) #2 /home/htdocs/ai/numphp/sciphp/numphp/src/SciPhp/NdArray/IndexTrait.php
(126): SciPhp\NdArray\Decorator->filterRange(Array, 0, 1) #3 /home/htdocs/ai/numphp/sciphp/numphp/src/SciPhp/NdArray/IndexTrait.php
(65): SciPhp\NdArray\Decorator->filterSet(Array, 0, Array, 1) #4 /
home/htdocs/ai/zeroml/rnn in
/home/htdocs/ai/numphp/webmozart/assert/src/Assert.php
on line 2042

I'm using these method np::argmax(), np::log(), np::exp(), np::sum(), np::tanh(), np::dot(), np::max()
and I Didn't find which among them throw this excption.
sorry for my bad english, I Speak frend

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.