We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi
i've been trying to create math class to do matrix math. but the class returns a null instead of matrix. if i put the function outside the class it works fine.
int input = 2, node = 6, output = 2;
float[][] inputs= new float[input][1], nodes = new float[node][1], outputs = new float[output][1], nodeBias = new
float[node][1], outputBias = new float[output][1];
float[][] inputsToNode = new float[node][input], nodeToOutput = new float[output][node];
Math m;
void setup() {
size(100, 100);
println(inputsToNode[5][1]);
inputsToNode = m.weightFill(inputsToNode, node, input);
println(inputsToNode[5][1]);
}
class Math {
float[][] weightFill(float[][] k, int Height, int Width) {
for (int i=0; i<Height; i++) {
for (int j=0; j<Width; j++) {
k[i][j] = random(-1, 1);
}
}
return k;
}
}
thanks
Answers
where do you instantiate m?
static
. *-:)static
as well. 8-|so i changed my math class >> to static class matrixMath {} but i use the random function and static does not love the random function :P gives me this: cannot make a static reference to the non static method random.
other suggestions? :)
You can use Java's Math.random() in place of Processing's random(): *-:)
https://Docs.Oracle.com/javase/9/docs/api/java/lang/Math.html#random--
But given the former returns a
double
value, you may need to downcast it w/(float)
. :ar!for your original problem, rename your Math class, something better then Math2. and instantiate m using:
then the original code won't give you an npe.
but, yes, as it is your class is pointless.
so maybe i should write the function in a new tab but before i create the matrixMath class?
There's loads of (java) libraries out there for doing Matrix math, why not just use one of them?