Do you want a sparse 3D array or will your array be "full", with no holes? If it's sparse, simply use a dict indexed by (x, y, z). If it's full, you can either use a list of lists of float lists, or numpy's arrays. numpy is a fairly cool library when you want to do computations on large arrays in Python.
I got a friend who was adamant for a while that python was the best non-C++ language to work out what to do. I ended up with this:
Code:
import bpy
import mathutils
import math
class MakeOneSOrbital(bpy.types.Operator):
bl_idname = "mesh.make_one_s_orbital"
bl_label = "Add 1s Orbital"
def invoke(self, context, event):
e = 2.71828182845904523536028747135266249775724709369995
psimax=0
psimin=2**31
res = 50
multi = 2*res
cubedim = 2.5/res
stretch = 5/res
psilist = [[[0 for k in range(res*2+1)] for j in range(res*2+1)] for i in range(res*2+1)]
for x in range(-res,res+1):
for y in range(-res,res+1):
for z in range(-res,res+1):
xco = x/multi
yco = y/multi
zco = z/multi
r = xco**2 + yco**2 + zco**2
r = r**0.5
psi=e**-r
if psi > psimax:
psimax = psi
if psi < psimin:
psimin = psi
psilist[x+res][y+res][z+res] = psi
print(psimax,psimin)
for x in range(-res,res+1):
for y in range(-res,res+1):
for z in range(-res,res+1):
xco = x/stretch
yco = y/stretch
zco = z/stretch
bpy.ops.mesh.primitive_cube_add(location=(xco,yco,zco))
bpy.ops.transform.resize(value=(cubedim,cubedim,cubedim))
mat = bpy.ops.material.new()
mat.type = 'VOLUME'
mat.volume.density = psimax/psilist[x+res][y+res][z+res]
return {"FINISHED"}
bpy.utils.register_class(MakeOneSOrbital)
I now just have the issues that Blender freezes after a script runs for more than a few seconds, and that, although the api says I'm doing it right, mat.type = 'VOLUME' crashes the script. Given how long it took to find that bit of the API, I'm not sure anyone actually knows what I'm supposed to do.
(10-07-2013, 09:18 AM)ExtremeDude2 Wrote: [ -> ]Already started work eh?
I'd have started earlier if people hadn't wasted my time arguing about the d3d9 removal...
Haven't posted here in a while. GB Enhanced is actually getting along nicely. Spent a bit of time doing CPU work, now I can pass all of Blargg's GB CPU tests. That's good, because now every issue is certainly down to either timings, memory access, or LCD emulation (but that's still a pretty wide area in and of itself). At any rate, I implemented full MBC1 support recently, so games that have RAM and battery backed RAM play, and I can even save some games (there's a bug somewhere and some games delete the saved data, but it works in some games). Finally fixed a pesky LYC/STAT interrupt issue that was giving me headaches with Mega Man. It's not much, but compatibility is already better than JSGB, so that's something at least.
There's still a lot of work to do (add custom sprites to the reworked emulated LCD, joystick support, save states, a few other STAT interrupts types, an in-app GUI like Mednafen or even better like PPSSPP SDL, sound, bug fixes) but I'm to the point where I can enjoyably play many of my favorite games. Kirby's Block Ball runs perfectly; it was the first game I ever had for the GB Pocket and it was a gift from my grandmother. I spent hours on Wario Land too, and that's almost 100% in GBE too (minor transparency issues + disappearing saves). Once more MBC support comes, I'll be able to start playing games like Pokemon. Can't wait to get around to implementing GameShark codes when I start playing Red Version :p
More pics, mind the increased size, I was playing with Nearest Neighbor 3x:
![[Image: jWOC72lFpykda.png]](http://i.minus.com/jWOC72lFpykda.png)
I'm reading the New Turing Omnibus, as it's something that knowing you've read encourages universities to let you do computer science, and found a chapter on neural nets. I then implemented the psuedocode in Java, and it was going well until I reached the point at which it was theoretically finished. It currently 'learns' how to convert polar coordinates to Cartesian coordinates for a bit, and then starts learning in the wrong direction (i.e. it gets worse than it was earlier) until the error is infinite, then a few cycles later, it starts returning NaN, which it isn't supposed to. Anyway, can anyone see where the issue is?
Code:
import java.util.Random;import java.lang.Math;
//This is broken, but follows the psuedocode perfectly. It is set to exit when something breaks. The error tends to infinity, leading things to break when a correction is attempted. The error problem is either caused by overflow, or division by zero.public class NeuralNet{ final double RATE = 0.1; double[][] synone = new double[2][30]; double[][] syntwo = new double[30][2]; double[] input = new double[2]; double[] medin = new double[30]; double[] medout = new double[30]; double[] output = new double[2]; double[] error = new double[2]; public void initialise() { //set synone to random values between -0.1 and 0.1 for(int i=0; i<30; i++) { for(int j=0; j<2; j++) { synone[j][i] = new Random().nextDouble(); synone[j][i] = synone[j][i]*0.2 - 0.1; } } //Same for syntwo for(int i=0; i<2; i++) { for(int j=0; j<30; j++) { syntwo[j][i] = new Random().nextDouble(); syntwo[j][i] = syntwo[j][i]*0.2 - 0.1; } } } public void run() { for(int i=0; i<=10000; i++) { //Generate polar coords on unit circle double length = 1.0; double theta = new Random().nextDouble(); theta = theta * 360.0; //put length and theta into input neurons input[0] = length; input[1] = theta; //Pass these to convert to get back error convert(input); //Use back propagation to adjust neural net backProp(); //Output error E double errorE = 0.0; for(int j=0; j<error.length; j++) { errorE = errorE + error[j]*error[j]; } errorE = Math.sqrt(errorE); System.out.println(errorE); } } public void convert(double[] input) { //for each medial neuron for(int i=0; i<30; i++) { //reset medial input medin[i] = 0; //for each input neuron for(int j=0; j<2; j++) { //add input times weight to the neuron medin[i] = medin[i] + synone[j][i]*input[j]; } //compute tanh of the neuron's value to get it's output medout[i] = Math.tanh(medin[i]); } double[] target = new double[2]; //for each output neuron for(int i=0; i<2; i++) { //reset output output[i] = 0; //for each medial neuron for(int j=0; j<30; j++) { //add input times weight to the neuron output[i] = output[i] + syntwo[j][i] * medout[j]; System.out.println("O"+output[i]+" S2"+syntwo[j][i]+" Mo"+medout[j]); if(Double.isNaN(output[i])) System.exit(0); } //compute correct value for this output //must use correct trig function for x and y switch(i) { case 1: target[i] = input[0] * Math.sin(Math.toRadians(input[1])); break; case 2: target[i] = input[0] * Math.cos(Math.toRadians(input[1])); break; default: break; } error[i] = target[i] - output[i]; } } public void backProp() { //adjust second synaptic layer //for each output neuron for(int i=0; i<2; i++) { //for each medial neuron for(int j=0; j<30; j++) { //adjust the synaptic multiplier/weight syntwo[j][i] = syntwo[j][i] + RATE*medout[j]*error[i]; } } //Derive the sigmoidal signal double[] sigma = new double[30]; double[] sigmoid = new double[30]; //for each medial neuron for(int i=0; i<30; i++) { //reset sigma sigma[i] = 0; //for each output neuron for(int j=0; j<2; j++) { //add value to sum sigma[i] = sigma[i] + error[j]*syntwo[i][j]; } //calculate sigmoid sigmoid[i] = 1 - medin[i]*medin[i]; } //adjust the first synaptic layer //probably for each output neuron, although that doesn't seem obvious for(int i=0; i<2; i++) { //for each medial neuron for(int j=0; j<30; j++) { double delta = RATE*sigmoid[j]*sigma[j]*input[i]; synone[1][j] = synone[i][j] + delta; } } } public static void main(String[] args) { NeuralNet net = new NeuralNet(); net.initialise(); net.run(); }}
Okay, code /code tags don't work. have the .java file.
Also, did you know that both .java and .ITMADEMECHANGETHEFILEEXTENSION are blocked from being attached by the forum.
Finally got a decent GB/GBC flashcart. No, this isn't to play games on (fwiw, the GB and GBC and even my original GBA are terribly hard to play these days without backlights) I got this so I could debug GB/GBC hardware for my emulator. Even though we have the GB programming manual from Nintendo available online, not even that freakin' explains everything (like how the LCD mode is reset when the LCD is disabled, and reset again when it's enabled, stupid stuff like that). I'm writing my own test ROMs (by hand with a hex editor)
I also got this kick-ass sticker:
Anyway, I've only really written one test ROM so far to test when LY and LYC registers are compared, and when LY is incremented by the hardware. It's incredibly difficult to see, but the test draws alternating lines of light and dark lines until a STAT interrupt disables the background (hence the white pixels for most of the screen). Depending on which color is last draw on an emulator, the emulator either passes (last color drawn = light) or fails (last color drawn = dark) to emulate the hardware accurately for this test. Naturally my emulator passes it (it didn't until a few commits ago). Got some other tests in mind (inaccessible OAM/VRAM). Now I can find out what the GB/GBC is doing exactly without having to try to decipher the incomplete documentation and the source code for 5 different other emulators:
Guess I'm officially working on the most awesome Dolphin branch, ever. o_o