Skip to content

korpusovmax/jtensors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 

Repository files navigation

Jtensors

  1. About
  2. Tensors
  3. Basic functions
  4. Examples
  5. TODO

About

WIP
Jtensors is a simple java library for working with Tensors. Jtensors supports working with different types of tensors and include basic functions like math operations, summation, product, reshaping, genearating arrays, transposing, activation functions (with deriv-s) etc.


Tensors

Here you can see all tensor types and their creation. There are some types of tensors: scalar (number), vector (list of numbers), matrix (list of vectors), ntensor(list of matrices/ntensors)

Scalar

Tensor l = new Tensor(0.6);

(With all Tensors you can use the System.out.println(tensor) or toString() function)

Vector

Tensor l = new Tensor(1, 2, 3);

Matrix

Tensor l = new Tensor(
        new Tensor(1, 2, 3),
        new Tensor(4, 5, 6)
    );
//instead of this you can use:
//double[][] data = new double[][]{
//        {1, 2, 3},
//        {4, 5, 6}
//};
//Tensor l = new Tensor(new Tensors.Matrix(data));

NTensor

Tensor l = new Tensor(
        new Tensor(1, 2, 3),
        new Tensor(4, 5, 6)
    );
Tensor m = new Tensor(l, l, l);

Basic functions

All information from this article has been deleted (temporarily) after changing the syntax of lib. It will be updated soon.


Examples

The simplest neural network

import me.korpusovmax.jtensors.*;

public class Main {
    public static void main(String args[]) {
        Tensor inputs = new Tensor(
                new Tensor(0, 0, 1),
                new Tensor(0, 1, 1),
                new Tensor(1, 0, 1),
                new Tensor(1, 1, 1)
                );
        Tensor target = new Tensor(0, 0, 1, 1).pack().T();

        Tensor syn0 = new Tensor(Tensors.random(3, 1));

        Tensor l1 = new Tensor(0);
        for (int i = 0; i < 10000; i++) {
            Tensor l0 = inputs;
            l1 = l0.dot(syn0).activate(Tensors.sigmoid);

            Tensor l1error = target.sub(l1);
            Tensor l1delta = l1.activate(Tensors._sigmoid).mul(l1error);
            syn0 = syn0.add(l0.T().dot(l1delta));
        }
        System.out.println(l1);
    }
}

Result:

[[0.0096677496361140],
 [0.0078629554744772],
 [0.9935914478825549],
 [0.9921178326055041]]

TODO

These are some plans for the upcoming features.

  • pack() and pack(int n) functions
  • transpose() function
  • getValue(int... i) and getDouble(int... i) functions
  • reshape() function
  • stream() function
  • maximum/minimum getters
  • filter(min, max) function
  • flatten() getter
  • fill() function
  • append/remove functions and creating Tensors without values

Releases

No releases published

Packages

No packages published

Languages