OpenMaple Java Interface - java
I am trying to use OpenMaple with Java interface to simply turn a matrix into reduced row echelon form. Ultimately I want to find the inverse of a matrix. I am not sure how to take a 2-d array in my program and make it interact with engine objects.
Some basic examples are here.http://www.maplesoft.com/support/help/Maple/view.aspx?path=OpenMaple/Java/Engine/evaluate
I basically want this: t.evaluate( "with(LinearAlgebra): A:=<<2,4,8>|<8,2,4>|<4,8,2>>; ReducedRowEchelonForm(A);" );
Problem 1: getting a 2-d matrix I made into that statement.
Problem 2: somehow making it output into another 2-d array as a result.
I don't know much about OpenMaple, therefore I come here. Thanks!
Related
Neural networks and Python
I'm trying to study about neural networks, following a great guide: http://neuralnetworksanddeeplearning.com/chap1.html Currently I've reached this code snippet which I'm trying to understand and write in Java: class Network(object): def __init__(self, sizes): self.num_layers = len(sizes) self.sizes = sizes self.biases = [np.random.randn(y, 1) for y in sizes[1:]] self.weights = [np.random.randn(y, x) for x, y in zip(sizes[:-1], sizes[1:])] I managed to figure out what everything means except for the last line: [np.random.randn(y, x) for x, y in zip(sizes[:-1], sizes[1:])] As far as I can understand: create a matrix with y rows and x columns, for each pair x,y which can be found in the matrix zip which is created by the merging of the two "sizes" arrays. I understand that sizes[1:] means taking all elements from sizes starting from index 1, but sizes[:-1] makes no sense to me. I read online that s[::-1] means getting the reverse of the array, but in the above case we only have one colon, while in the formula for the reverse array there seems to be two colons. Sadly, I have no idea how Python works and I got pretty far along with the online book to give it up now (I also truly like it), so can someone say if I'm right until now, correct me if needed, or straight out explaining that final line?
sizes[:-1] is a list slice which returns a copy of the sizes list but without the last item.
Code will not compile, as it's "too large", even though the entire class is just data
I'm using NetBeans 8.1, trying to create a 2D array of impulse filters, each of which is an array of 128 doubles. I've generated text like this: (Note that I've replaced most of the double[] values with ... to make it easier to read). There are about 380 of these: double[] left_H80e000a={0.1250000,-0.0390930,0.1328125...,0.7511292}; double[] left_H80e030a={-0.0390930,0.1406250,-0.0390930,...0.7511292}; double[][][] left_filters={ {left_H_40e000a,null,left_H_40e006a,left_H_40e013a,left_H_40e019a,null,left_H_40e026a,left_H_40e032a,left_H_40e039a,left_H_40e045a,null,left_H_40e051a,left_H_40e058a,left_H_40e064a,null,left_H_40e071a,left_H_40e077a,left_H_40e084a,left_H_40e090a,null,left_H_40e096a,left_H_40e103a,left_H_40e109a,null,left_H_40e116a,left_H_40e122a,left_H_40e129a,left_H_40e135a,null,left_H_40e141a,left_H_40e148a,left_H_40e154a,null,left_H_40e161a,left_H_40e167a,left_H_40e174a,left_H_40e180a} ,{left_H_30e000a,null,left_H_30e006a,left_H_30e012a,left_H_30e018a,left_H_30e024a,left_H_30e030a,null,left_H_30e036a,left_H_30e042a,left_H_30e048a,left_H_30e054a,left_H_30e060a,null,left_H_30e066a,left_H_30e072a,left_H_30e078a,left_H_30e084a,left_H_30e090a,null,left_H_30e096a,left_H_30e102a,left_H_30e108a,left_H_30e114a,left_H_30e120a,null,left_H_30e126a,left_H_30e132a,left_H_30e138a,left_H_30e144a,left_H_30e150a,null,left_H_30e156a,left_H_30e162a,left_H_30e168a,left_H_30e174a,left_H_30e180a} ,{left_H_20e000a,left_H_20e005a,left_H_20e010a,left_H_20e015a,left_H_20e020a,left_H_20e025a,left_H_20e030a,left_H_20e035a,left_H_20e040a,left_H_20e045a,left_H_20e050a,left_H_20e055a,left_H_20e060a,left_H_20e065a,left_H_20e070a,left_H_20e075a,left_H_20e080a,left_H_20e085a,left_H_20e090a,left_H_20e095a,left_H_20e100a,left_H_20e105a,left_H_20e110a,left_H_20e115a,left_H_20e120a,left_H_20e125a,left_H_20e130a,left_H_20e135a,left_H_20e140a,left_H_20e145a,left_H_20e150a,left_H_20e155a,left_H_20e160a,left_H_20e165a,left_H_20e170a,left_H_20e175a,left_H_20e180a} ,{left_H_10e000a,left_H_10e005a,left_H_10e010a,left_H_10e015a,left_H_10e020a,left_H_10e025a,left_H_10e030a,left_H_10e035a,left_H_10e040a,left_H_10e045a,left_H_10e050a,left_H_10e055a,left_H_10e060a,left_H_10e065a,left_H_10e070a,left_H_10e075a,left_H_10e080a,left_H_10e085a,left_H_10e090a,left_H_10e095a,left_H_10e100a,left_H_10e105a,left_H_10e110a,left_H_10e115a,left_H_10e120a,left_H_10e125a,left_H_10e130a,left_H_10e135a,left_H_10e140a,left_H_10e145a,left_H_10e150a,left_H_10e155a,left_H_10e160a,left_H_10e165a,left_H_10e170a,left_H_10e175a,left_H_10e180a} ,{left_H0e000a,left_H0e005a,left_H0e010a,left_H0e015a,left_H0e020a,left_H0e025a,left_H0e030a,left_H0e035a,left_H0e040a,left_H0e045a,left_H0e050a,left_H0e055a,left_H0e060a,left_H0e065a,left_H0e070a,left_H0e075a,left_H0e080a,left_H0e085a,left_H0e090a,left_H0e095a,left_H0e100a,left_H0e105a,left_H0e110a,left_H0e115a,left_H0e120a,left_H0e125a,left_H0e130a,left_H0e135a,left_H0e140a,left_H0e145a,left_H0e150a,left_H0e155a,left_H0e160a,left_H0e165a,left_H0e170a,left_H0e175a,left_H0e180a} ,{left_H10e000a,left_H10e005a,left_H10e010a,left_H10e015a,left_H10e020a,left_H10e025a,left_H10e030a,left_H10e035a,left_H10e040a,left_H10e045a,left_H10e050a,left_H10e055a,left_H10e060a,left_H10e065a,left_H10e070a,left_H10e075a,left_H10e080a,left_H10e085a,left_H10e090a,left_H10e095a,left_H10e100a,left_H10e105a,left_H10e110a,left_H10e115a,left_H10e120a,left_H10e125a,left_H10e130a,left_H10e135a,left_H10e140a,left_H10e145a,left_H10e150a,left_H10e155a,left_H10e160a,left_H10e165a,left_H10e170a,left_H10e175a,left_H10e180a} ,{left_H20e000a,left_H20e005a,left_H20e010a,left_H20e015a,left_H20e020a,left_H20e025a,left_H20e030a,left_H20e035a,left_H20e040a,left_H20e045a,left_H20e050a,left_H20e055a,left_H20e060a,left_H20e065a,left_H20e070a,left_H20e075a,left_H20e080a,left_H20e085a,left_H20e090a,left_H20e095a,left_H20e100a,left_H20e105a,left_H20e110a,left_H20e115a,left_H20e120a,left_H20e125a,left_H20e130a,left_H20e135a,left_H20e140a,left_H20e145a,left_H20e150a,left_H20e155a,left_H20e160a,left_H20e165a,left_H20e170a,left_H20e175a,left_H20e180a} ,{left_H30e000a,null,left_H30e006a,left_H30e012a,left_H30e018a,left_H30e024a,left_H30e030a,null,left_H30e036a,left_H30e042a,left_H30e048a,left_H30e054a,left_H30e060a,null,left_H30e066a,left_H30e072a,left_H30e078a,left_H30e084a,left_H30e090a,null,left_H30e096a,left_H30e102a,left_H30e108a,left_H30e114a,left_H30e120a,null,left_H30e126a,left_H30e132a,left_H30e138a,left_H30e144a,left_H30e150a,null,left_H30e156a,left_H30e162a,left_H30e168a,left_H30e174a,left_H30e180a} ,{left_H40e000a,null,left_H40e006a,left_H40e013a,left_H40e019a,null,left_H40e026a,left_H40e032a,left_H40e039a,left_H40e045a,null,left_H40e051a,left_H40e058a,left_H40e064a,null,left_H40e071a,left_H40e077a,left_H40e084a,left_H40e090a,null,left_H40e096a,left_H40e103a,left_H40e109a,null,left_H40e116a,left_H40e122a,left_H40e129a,left_H40e135a,null,left_H40e141a,left_H40e148a,left_H40e154a,null,left_H40e161a,left_H40e167a,left_H40e174a,left_H40e180a} ,{left_H50e000a,null,left_H50e008a,null,left_H50e016a,left_H50e024a,null,left_H50e032a,left_H50e040a,null,left_H50e048a,null,left_H50e056a,left_H50e064a,null,left_H50e072a,left_H50e080a,null,left_H50e088a,null,left_H50e096a,left_H50e104a,null,left_H50e112a,left_H50e120a,null,left_H50e128a,null,left_H50e136a,left_H50e144a,null,left_H50e152a,left_H50e160a,null,left_H50e168a,null,left_H50e176a} ,{left_H60e000a,null,left_H60e010a,null,left_H60e020a,null,left_H60e030a,null,left_H60e040a,null,left_H60e050a,null,left_H60e060a,null,left_H60e070a,null,left_H60e080a,null,left_H60e090a,null,left_H60e100a,null,left_H60e110a,null,left_H60e120a,null,left_H60e130a,null,left_H60e140a,null,left_H60e150a,null,left_H60e160a,null,left_H60e170a,null,left_H60e180a} ,{left_H70e000a,null,null,left_H70e015a,null,null,left_H70e030a,null,null,left_H70e045a,null,null,left_H70e060a,null,null,left_H70e075a,null,null,left_H70e090a,null,null,left_H70e105a,null,null,left_H70e120a,null,null,left_H70e135a,null,null,left_H70e150a,null,null,left_H70e165a,null,null,left_H70e180a} ,{left_H80e000a,null,null,null,null,null,left_H80e030a,null,null,null,null,null,left_H80e060a,null,null,null,null,null,left_H80e090a,null,null,null,null,null,left_H80e120a,null,null,null,null,null,left_H80e150a,null,null,null,null,null,left_H80e180a} ,{left_H90e000a,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null} }; I've had much larger arrays in past code, one of which is 26 arrays containing 60,000 strings, so I'm baffled as to why this isn't possible. Firstly, there's no code, secondly, does anyone have a better way to embed large data structures in Java?
Well there is code. This is converted to bytecode, somewhere the JVM will have to load these number in memory, you can have a guess as what the code will look like here: How does Arrays work in the ByteCode of Java The worst solution I could think of would creating one class per array (like a Left_H80e000a class and statically calling them for your 3D arrays. But honestly, create a CSV file and read from it. Like, you make aleft_H80e000a.csv" with the same data, read from it then put it in your 3D array. (isn't double[] left_H80e000a= readFromCSV("left_H80e000a.csv"); cleaner ?..) I guess a class file with only the 3D array should be fine. Some comments stated to use a database. That's an idea, but there is no point building a database if that's your only use.
Insertion in 3D arraylist
I have created 3D ArrayList. I know initialization is done using this code ArrayList<ArrayList<ArrayList>> ll=new ArrayList<ArrayList<ArrayList>>(); for(int j=0;j<n;j++){ ll.add(new ArrayList(new ArrayList())); } But I dont know how insert values in it. I am familiar with 2D arraylist in which inserting value b at a index is done using ll.get(a).add(b); but I dont know how to insert value into 3D arrayList. I am solving question http://www.spoj.com/problems/BENEFACT/ in which I think longest distance in tree is the answer. I used 3D ArrayList here, 2dimension to store connection of places and 3rd dimension to store distance Is this correct approach? Is Any other approach possible in which solution is obtained easier than using 3d ArrayList?
I think if you want to access an object at index i,j,k you can do it by ll.get(i).get(j).get(k) Or ll.get(i).get(j).add(k,newObject)
Depending on your need, you probably don't want that. I didn't read the full description of the problem to solve (the link), but you just need 6 points in 3D space. I'd suggest creating a Point3D class with x, y, and z, and then just a simple List<Point3D>.
Combinatorics in Java with trees
For a project that I'm currently working on I am dealing with a list of lists of integers, something of the form: {[1,2];[5];[3,6,7]} The idea here is that I'm trying to resolve an n-dimensional array into a list of the local maxima that occur in whatever particular axis I happen to be looking at. My question is this: I would like to get out a list of what would essentially be points in this n-dimensional space that contains every possible combination of entries of this list. For example, I would want the above to return: {[1,5,3];[1,5,6];[1,5,7];[2,5,3];[2,5,6];[2,5,7]} With the ordering not actually mattering to me. My first idea in how to approach this would be to boil this down to a tree where each path represents a possible combination and outputting every possible path, but I'm really not sure if this is the best way of going about it, and I am unfamiliar enough with Java's tree classes to be unsure if this would actually be straightforward to implement or not. Ideas? Ah, my mistake, totally a duplicate.
How to store table or matrix in Java?
I used to use matrix in octave to store data from data set, in Java how can I do that? Assume I have 10-20 columns and large data, I don't think int [][]data; would be the best option. Is nested map the only solution?
You could create a class Coordinate that takes an X and Y values and properly implement hashCode and equals. Then create a HashMap<Coordinate, Data> and work with it.
Depends on what you need to do. If you know the size of the lists, then an array is definitely ideal since it means you will have instant access (read/write time) to any position in the array, this is very useful for speed. Maps are better if you dont know the size and it needs to be able to adapt. And finally, as I discovered in a previous question, if you have a TON of data, and a lot of it will be "0" you might want to also consider using a Sparse Martrix
This answer merges some of gnomed's answer and SJuan76's answer contents. At a quick glance, I'd suggest you to use bidimentional arrays such as int[][]. It's not a very huge amount of data (we're speaking of ≈500 ints) so it's not a bad idea. Advantages: It's the simpler, ideal (from the data-structuring side) way to go, especially if every “slot” of the matrix contains data. The inconvenient: You have to know the size of the matrix before constructing it. Anyway, you can resize it later using the Arrays utilities. If you want more effective handling of the data, you can use a single point-map. That is, the key of every entry is a java.awt.Point that defines where is the value located. Advantages: It's more effective than having a 2D array, especially if part of your matrix doesn't contain data. And it's adaptative; you don't need to know any sizes to construct/resize it. The inconvenient: If every “slot” of your matrix contains data, you'll loose (a lot of) space and performance. A 2D-array is more effective then. Want more? If your data is really huge you can use a sparse matrix. See this question for more details.
I would not discard multidimensional arrays so far: have you tried them? Are you finding specific limitations? IMHO as long as your data fits in memory, arrays can be good. If your data is very sparse though, you may want to look at maps indeed. Related question btw: Making a very large Java array
You can use multidimensional arrays or you can try any pairs like HashMap
I think multi-dimentional arrays are the best choice! They should serve your purpose. If your data set is only integers, int [] [] is an ideal choice.
Well, if your indices are small integers, you can certainly use nested arrays. In a matrix class, you may want to use a plain array, like so: (assuming n is the number of columns) double get(int i, int j) { return data[i*n + j]; } For a general table (sparse matrix), you can use nested maps, but consider using com.google.common.collect.Table implementations from the Google Guava library.