Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 349 350 [351] 352 353 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 886269 times)

Maklak

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5250 on: November 25, 2013, 06:05:45 am »

Well, I don't really understand how it works (partly because a lot of it is missing), but if predicted converges to 1 or 0 then this will also return 0:
error = predicted * (1-predicted) * (real - predicted);

This one is also likely to return 0:
return error * weights;

So my guess is: Check the error propagation for nodes, then try to feed the network the same dataset over and over and see what happens with errors and weights.
Logged
Quote from: Omnicega
Since you seem to criticize most things harsher than concentrated acid, I'll take that as a compliment.
On mining Organics
Military guide for FoE mod.
Research: Crossbow with axe and shield.
Dropbox referral

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5251 on: November 25, 2013, 05:07:58 pm »

Okay, I wrote the same thing from scratch to see where you could get stuck, and I have no problems at all; I get really good results right from the beginning. The problem now is that I see no differences between my code and yours. Here's my program code if you want to compare (it's Java because... reasons).
Code: [Select]
package neural;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;

public class NeuralNetwork {

private HashSet<Node> nodes = new HashSet<Node>();

public NeuralNetwork() {
}

public void addNode(Node node) {
nodes.add(node);
}

public void train(HashMap<Node, Double> inputs, Node outputNode, double target, double learnSpeed) {
for (Node node : nodes) {
node.reset();
if (inputs.containsKey(node)) {
node.isInput = true;
node.input = inputs.get(node);
}
}
double result = outputNode.output();
outputNode.setAsOutput();
HashMap<Node, Double> errors = new HashMap<Node, Double>();
for (Node node : nodes) {
errors.put(node, node.calculateError(target, result));
}
for (Node node : nodes) {
node.applyError(learnSpeed, errors.get(node));
errors.put(node, 0.0);
}
}
public double ask(HashMap<Node, Double> inputs, Node outputNode) {
for (Node node : nodes) {
node.reset();
if (inputs.containsKey(node)) {
node.isInput = true;
node.input = inputs.get(node);
}
}
return outputNode.output();

}

public static class Node {
private final HashMap<Node, Double> inputs = new HashMap<Node, Double>();
private final HashMap<Node, Double> outputs = new HashMap<Node, Double>();
private final ActivationFunction phi;
public double input = 0;
public boolean isInput = false;
public double affinity = 0;
private boolean inputTotalDone = false;
private double inputTotal;
private boolean do_dresDone = false;
private double do_dres;
private String name;
public Node(String name, ActivationFunction af) {
this.name = name;
this.phi = af;
}

public void reset() {
inputTotalDone = do_dresDone = isInput = false;
}

public double inputTotal() {
if (inputTotalDone) {
return inputTotal;
} else {
inputTotalDone = true;
inputTotal = affinity;
for (Node in : inputs.keySet()) {
inputTotal += inputs.get(in)*in.output();
}
return inputTotal;
}
}
public double output() {
if (isInput) return input;
return phi.f(inputTotal());
}

public double d_output() {
return phi.df(inputTotal());
}

public void setAsOutput() {
do_dresDone = true;
do_dres = 1;
}

// Total output change per node output change
public double do_dres() {
if (do_dresDone) {
return do_dres;
} else {
do_dresDone = true;
do_dres = 0;
for (Node on : outputs.keySet()) {
do_dres += on.do_dres()*outputs.get(on)*on.d_output();
}
return do_dres;
}
}

public double calculateError(double target, double result) {
/*
* E = result error;
* o = total result;
* res = this output;
* net = this net sum;
*/
double dE_do = result - target;
double dres_dnet = d_output();
return dE_do * do_dres() * dres_dnet;
}

public void applyError(double learnSpeed, double error) {
for (Node in : inputs.keySet()) {
double w = inputs.get(in);
w -= in.output()*learnSpeed*error;
setInput(in, w);
}
affinity -= learnSpeed*error;
}

private void setInput(Node inputtingNode, double weight) {
inputs.put(inputtingNode, weight);
inputtingNode.outputs.put(this, weight);
}

public void printInfo() {
System.out.println("Node " + name + " (input " + input + ", affinity " + affinity + "):");
for (Node inputNode : inputs.keySet()) {
System.out.println("\tWeight from " + inputNode.name + ": " + inputs.get(inputNode));
}
System.out.println("\tOutput: " + output());
for (Node outputNode : outputs.keySet()) {
System.out.println("\tWeight to " + outputNode.name + ": " + outputs.get(outputNode));
}
}

public static interface ActivationFunction {
double f(double x);
double df(double x);
}
public static class LinAF implements ActivationFunction {

@Override
public double f(double x) {
return x;
}

@Override
public double df(double x) {
return 1;
}

}
public static class LogisticAF implements ActivationFunction {

@Override
public double f(double x) {
return 1/(1+Math.exp(-x));
}

@Override
public double df(double x) {
return f(x)*(1-f(x));
}

}
}
public static void main(String[] args) {
Random rand = new Random();
Node a = new Node("a", new Node.LinAF());
Node z = new Node("z", new Node.LinAF());
NeuralNetwork n = new NeuralNetwork();
n.addNode(a);
n.addNode(z);
for (int i = 1; i <= 8; ++i) {
Node q = new Node("q"+i, new Node.LogisticAF());
n.addNode(q);
q.setInput(a, rand.nextDouble());
q.affinity = rand.nextDouble();
z.setInput(q, rand.nextDouble());
}
z.affinity = rand.nextDouble();
HashMap<Node, Double> inputs = new HashMap<Node, Double>();
for (int i = 0; i < 1000000; ++i) {
double j = 2*rand.nextDouble()-1;
inputs.put(a, j);
n.train(inputs, z, targetFunc(j), 0.3);
if (i % 200000 == 0) {
for (Node node : n.nodes) {
node.printInfo();
}
System.out.println("Input: " + j + ", Target: " + targetFunc(j) + ", Result: " + z.output());
System.out.println();
System.out.flush();
}
}
for (double j = -1; j < 1; j += 0.05) {
inputs.put(a, j);
System.out.println(targetFunc(j) + ", " +  n.ask(inputs, z) + " ;");
}
}

public static double targetFunc(double x) {
return Math.sin(8*x);
}

}
Logged

Zrk2

  • Bay Watcher
  • Emperor of the Damned
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5252 on: November 25, 2013, 11:31:02 pm »

-snip-

Funfact: I was only losing ~3% of my roles with that one. However, it's too late to change it now, and I detest getting solutions handed to me.
Logged
He's just keeping up with the Cardassians.

dragnar

  • Bay Watcher
  • [Glub]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5253 on: November 26, 2013, 01:02:06 am »

Aha! Yeah, most of what I posted was pretty similar there - but, well, being forced to go through code slowly to compare it to another example most definitely helped me locate my error (Namely, there was a bug in the function used to re-initialize things between examples). Thanks, I'd not been able to find any raw code examples in a language I actually understood.

...course, the actual data set I'm using it on, as opposed to the test set, still ends up being learned horribly. But this is a research paper, so a negative result is just as useful as a positive on on that count.
Logged
From this thread, I learned that video cameras have a dangerosity of 60 kiloswords per second.  Thanks again, Mad Max.

Lightningfalcon

  • Bay Watcher
  • Target locked. Firing main cannon.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5254 on: November 29, 2013, 03:48:33 pm »

So I've decided to go ahead and start learning graphics for java.  First off, would it be better to learn awt, swing, or something else first?  Secondly, does anyone know some good tutorials? 
Logged
Interdum feror cupidine partium magnarum circo vincendarum
W-we just... wanted our...
Actually most of the people here explicitly wanted chaos and tragedy. So. Uh.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5255 on: November 29, 2013, 05:26:51 pm »

So I've decided to go ahead and start learning graphics for java.  First off, would it be better to learn awt, swing, or something else first?  Secondly, does anyone know some good tutorials?

Swing over AWT. AWT has some horrible issues with multi-threading, and Swing was created to replace it. As for a tutorial, http://docs.oracle.com/javase/tutorial/uiswing/components/.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5256 on: December 10, 2013, 06:06:00 am »

Ugh, my IDE inserted 4 spaces for every single tab in my project, and I didn't realize that before I already pushed it to github.

Now I got this unhelpful monster of a commit:

T_T

Any help on how to fix this mess? :S I suspect that I won't be able to, without losing any of the work I actually did.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5257 on: December 10, 2013, 08:05:47 am »

Any help on how to fix this mess?

Celebrate that you no longer use tabs?

If I recall correctly, GitHub doesn't like manipulating history. If you can't amend your commit and then force push, you'll have to make a separate commit with the spaces converted back to tabs.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5258 on: December 10, 2013, 09:18:14 am »

After a lot of failed derps, I just formatted my entire project to use tabs again. On the positive side this now enables MSVS's smart indent thingy. On the negative side, I ended up with 2000 additions and deletions...

I also fixed a bug!
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #5259 on: December 10, 2013, 10:09:31 am »

im in a huge ass developer conference in new orleans this week.

also, ive gotten a new project under my belt at work, and that came with a cubicle with a view if the gulf, instead of a forld up table bloking the basement fire escape.

ive also had to be doing some researh on javasript mvc libraries, and have found they all kinda suck, may be architecting a cleaner solution
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #5260 on: December 10, 2013, 12:56:57 pm »

So having played around with Typescript, I can safely say I prefer it over Javascript.

But I am rather of the opinion that compile-time constraints on functions are good. I just find it much easier to comprehend the behaviour of a function with n parameters when the possible usages of those n parameters isn't infinity*n. It's about reducing the cognitive load by being explicit about the responsibilities of a variable. Most coding mistakes come from Moore's Law and not Malice, reducing cognitive load reduces the amount the programmer must track in their head reduces the amount of potential applications of Moore's Law.

Unfortunately it doesn't fix Javascript's stupid variable hoisting behaviour. If Javascript at least had built-in support for functional Linq/MapReduce behaviour that'd at least remove the problems caused by hoisting xD But since that behaviour can only be provided by 3rd party libraries, and the function syntax required is overly verbose, I still call it a problem with the language. Just because issues have workarounds does not give issues reason to exist.

Basically, what I'd love to see as a language that compiles down to Javascript and is something like Scala crossed with Coffeescript. Take the functional programming, add the ability to set Constraints and explicitly declare variables provided by Scala, and give it the Ruby/Python-esque code structure of Coffeescript.

So something that looks more like:
Spoiler (click to show/hide)

Note that that example would be entirely statically typed, but with sufficient type-deduction that explicitly declaring types is completely pointless. Not figured out how I'd like functions to look with the static. Of course there are probably situations that break that kind of specification, since this is just me quickly going over that code and changing the syntax to a way I find more appealing.
« Last Edit: December 10, 2013, 01:25:03 pm by MorleyDev »
Logged

ECrownofFire

  • Bay Watcher
  • Resident Dragoness
    • View Profile
    • ECrownofFire
Re: if self.isCoder(): post() #Programming Thread
« Reply #5261 on: December 10, 2013, 09:04:16 pm »

But I am rather of the opinion that compile-time constraints on functions are good. I just find it much easier to comprehend the behaviour of a function with n parameters when the possible usages of those n parameters isn't infinity*n. It's about reducing the cognitive load by being explicit about the responsibilities of a variable. Most coding mistakes come from Moore's Law and not Malice, reducing cognitive load reduces the amount the programmer must track in their head reduces the amount of potential applications of Moore's Law.

Exactly why I prefer static typing to dynamic typing. You shouldn't trust your users, so that necessitates checking every argument to every function every time you call one. It's a ton of overhead for a very minor gain, and if you're using a functional language then it's zero gain at all because you can't reassign the damn things anyway. And I don't just mean overhead in performance or RAM, either. Dynamic typing basically requires the programmer to look up or remember the required types for the functions they want to use. I want to be able to know what kind of types a function wants by looking at a single line.

Also "users" above includes the various programmers who might not... "understand" some things. And even great programmers can be confused whether an absolute value function wants a float, double, or any of the various integer types (though in many dynamically typed languages there is only one number type).
Logged

Maklak

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5262 on: December 11, 2013, 12:25:45 pm »

Would you recommend a book to learn ASP .NET C#, preferably for a C++ programmer?
Logged
Quote from: Omnicega
Since you seem to criticize most things harsher than concentrated acid, I'll take that as a compliment.
On mining Organics
Military guide for FoE mod.
Research: Crossbow with axe and shield.
Dropbox referral

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #5263 on: December 11, 2013, 02:27:55 pm »

Would you recommend a book to learn ASP .NET C#, preferably for a C++ programmer?
msdn.com
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Aptus

  • Bay Watcher
  • Indeed ôo
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5264 on: December 14, 2013, 05:23:06 am »

Dear shit this login system is making me go insane. I am following the guide on http://www.codeproject.com/Articles/575551/User-Authentication-in-Ruby-on-Rails#CreatingtheUserModel26 with some minor modifications (basically just more stuff to enter when registering and without the ability to email).

I created the authentication system and the sign in function and when testing it since I have no users it should flash a message that says "uknown username or password" but instead the entire page freaks out.

I need some help from someone who knows a bit of Ruby on Rails.


Spoiler: Sign In (click to show/hide)

Spoiler: User model (click to show/hide)

I made sure I have all the required gems and stuff so that is not the issue. I can get to the sign in page just fine, but when I click the button to log in. This is what I get.

Spoiler (click to show/hide)

I have double, triple and quadruple checked that all the syntax I have written seems correct and right now I am tearing my hair out with a deadline on monday approaching.

EDIT: I think I have isolated the part that is causing trouble at least. I started testing shit again in the authentication_controller and when doing this:
Spoiler (click to show/hide)
I get redirected to the index page and it correctly flashes the username I entered in the form. So things seem to be passed correctly atleast.

EDITEDIT: Sorry for the long ass post, but bananastand.

I have now isolated the problem to lie within the render :action part of the else statement that is supposed to keep you on the login page if you enter faulty credentials. Now to figure out what is wrong with it.

EDITEDITEDIT:
Ok... changed it to a redirect_to and now it works... son of a bastard dove...
« Last Edit: December 14, 2013, 07:11:55 am by Aptus »
Logged
Pages: 1 ... 349 350 [351] 352 353 ... 796