Tensors

edited October 2016 in Programming Questions

Hi,

Is it possible to use tensors in Processing?

Answers

  • edited October 2016 Answer ✓

    What are you using tensors for? Graphs / neural networks / deep learning?

    I'm not aware of tensor libraries specifically for Processing, but there are ones available for Java, which you could use in Processing (or for Python, with Processing Python mode).

    Or if you don't need a network / learning framework and just want a generic tensor object class, you could write one based on PVector. Java 8 doesn't have full closures, but it does have lambdas.

  • Answer ✓

    (or for Python, with Processing Python mode).

    Python Mode is based on Jython. And can only use Java libraries. :(

  • edited October 2016 Answer ✓

    Java 8 doesn't have closures, ...

    Actually all Java versions got limited closure. You can see an example at the link below:
    https://forum.Processing.org/two/discussion/18517/timing-for-draw-loop#Item_23

  • Answer ✓

    ... but it does have lambdas.

    Java 8's lambdas can also grab final-like local variables the same way local class instantiations do. :-bd

  • edited October 2016

    Thanks for your answers.

    The usage I am wondering about is having a couple of spheres connected and let them; shrink, expand, rotate, move. Based on a calculation of their given values and the tension between them, such as in a network of springs, where they push or pull each other, and adding possibly a changing roomtemperature. So basically a bunch of different imputs.

    Note, I am just dipping my toes in the water to get some idea of how to approach this, I am far from being an expert, and tensors sounded like something that could handle the multitude of inputs. BTW not necessarily for a grid but perhaps more for freely moving spheres, maybe in that case tensors are already a no go?

  • edited October 2016 Answer ✓

    @chelle -- for your usage, you might just try extending PVector or else using the PVector source to make your own class. You don't need the tensorflow library to model heated springs.

    In fact, if all of your vectors are using the same formula (and the same on 3 dimensions) you don't even need closures / lambdas. You just hard-code the parametrized method in the class.

    You may want to look at "force-directed graphs"/layout as a category of algorithms for what you are describing.

  • When you mention "freely moving spheres" are you thinking of flocking algorithms? Or force-directed graph algorithms?

    In order to create loops / knots etc. will they be making and breaking temporary bonds all the time, like birds flocking?

    Or will particles form relatively permanent edge bonds with others (like chemical bonds) -- force-directed?

  • @GoToLoop -- an aside question re:above Python Mode / Jython can only use Java libraries.

    according to forum member GoToLoop ;) Python libraries work fine unless they are compiled C. Is this no longer true? Looking around, it seems Jython even comes with the pip installer now -- although I haven't tested this with processing.

  • Python libraries work fine unless they are compiled C. Is this no longer true?

    It is true! If we got the source code, of course we can use it in Jython.
    But in general, I think many famous Python libraries are C-compiled, both for speed & hardware access, aFaIK. Not so sure b/c I barely know any Python. Just learned a little to answer some Python Mode questions here! @-)

  • edited October 2016

    What are you using tensors for? Graphs / neural networks / deep learning?

    The goal of projects is to create a tessellation of cells similar to a foam …

    … and get these cells to move around.

    Hopefully one day in circles like these cyclists:

    As a reference you could check out this clip, where a 'player' can move the cells.

    https://vimeo.com/28695440

    What we want to have are cells that move around with out a 'player'.

    Here for I like to introduce the idea of using currents between the cells.

    • This gives rise to 2 elements: Volumes (OO) and Currents (>--<)

    • Within this tessellation all the cells are pressed together and have different tensions between them.

    • The pressure between the currents influences how much current there can be and visa versa.

    • Think of a landscape full of rivers, the harder the rivers run the more sand they drag along; the less the rivers can flow the more sand start to pile up.

    • Thus cells can shrink and expand and are being pushed around:

    With more cells we can start to have a whole circuit; where the white arrows represent a Voronoi tessellation and the black graphs a Delaunay triangulation, both graphs are dual to each other.

    The question is how to have a current-circuit that doesn't settle down? The currents need to keep on running so the cells can keep moving/changing possition.

    One option might be using Attraction - Separation forces like in this sketch:

    https://vimeo.com/141067668

    … and using magnetic points (-)(+) at the end of each current-line, along with a timer like an hourglass; where points grow or shrink depending on the time they are connected, pushing flow from A to B.

    Think of this ‘Magz' toy to build structures:

    The toy-magnets keep their potential but if they would change in strength depending on their connection-time everything can start to grow, shrink, jiggle and move.

    --

    Thus if we can have a dynamic network of moving currents, than cells could move and patterns of flow can form within a foam.

    In 3D the whole setup would look a bit like this but dynamic

  • edited October 2016

    @jeremydouglass,

    When you mention "freely moving spheres" are you thinking of flocking algorithms? Or force-directed graph algorithms?

    Not sure, in the case of the yellowish Voronoi-tessellation they used fortune's algorithm.

    I see these spheres/particles more like magnetic repulsive particles. Flocking would make them follow something and there is nothing to follow.

    Here I am talking about the volume-cells (OO); but maybe for the currents, flocking might make sense, as the current from particle A flows to particle B (A>—<B)

    In order to create loops / knots etc. will they be making and breaking temporary bonds all the time, like birds flocking?

    I don’t think that is needed as the particles would change position due to changes in size. In a Voronoi-tessellation bonds, and I am here talking about edges of the tessellation, can disappear or show up.

    Or will particles form relatively permanent edge bonds with others (like chemical bonds) -- force-directed?

    No, nothing permanent, you mean as if there is some ‘click’ that gets two particles hooked?

    As long as currents ‘sustain’ a cell, the cell can keep on existing. But if the moment a branch of the current tree would start to get ‘cut-off’, than this will have its effect on the cells, that's how 'bonds' will start to fade.

  • @chelle -- this sounds like the relevant class of algorithm might actually be fluid dynamics. If you are packing a space (foam) you don't need a graph at all, and if the cells aren't agents then flocking isn't relevant. You can Even make the fluid dynamic independent of the cells and have them just react, then add feedback.

  • From the Processing Libraries page, check out PixelFlow and punktiert

  • edited October 2016

    You can Even make the fluid dynamic independent of the cells and have them just react, then add feedback.

    Mh, yes, something like this exists, where the Voronoi-mesh allows for a numerical representation of the fluid.

    But there is no current-circuit that runs inbetween the cells and interacts with the cells, in normal fluid dynamic everything is calculated from one cell to its neighbors.

    What I'm thinking of is more like Game of Life where a calculation is made in a different way.

    What I am looking here for are two systems interacting, not a tessellation that represents what is going on underneath.

    The latter part of your suggestion "just react" and "add feedback" that's where the difficulty lies. For neighboring cells there needs to be a tension between the cells calculated, not only the 'passing on' of vallues, therfor the question of tensors, where other things can be added.

    Mh, just thinking out load here, …

  • edited November 2016

    @chelle --

    1. Lee Byron's mesh library for Processing supports both Delaunay triangulation and Voronoi diagrams.
    2. Toxiclibs for Processing also has classes for both Delaunay and Voronoi.

    If you need tensors to connect them maybe one of these Java libraries will provide something off-the-shelf (or a model):

    1. SemSim has a Tensor class
    2. as does JSci
    3. Stanford JNLP has SimpleTensor.

    See also old discussion: https://forum.processing.org/one/topic/voronoi-tesselation-diagram-process-on-a-picture.html

Sign In or Register to comment.