sciphp / numphp Goto Github PK
View Code? Open in Web Editor NEWPHP tools for matrix computation
Home Page: https://sciphp.org
License: MIT License
PHP tools for matrix computation
Home Page: https://sciphp.org
License: MIT License
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);
}
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!
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
Can you fix the site, or upload the docs to git so they're still readable?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.