Hacker News new | past | comments | ask | show | jobs | submit login
cPerceptron: A neural network (Simple Perceptron) implemented in PHP. (github.com/gzanitti)
25 points by gzanitti on Dec 15, 2012 | hide | past | favorite | 19 comments



This makes me think I should upload my random computational intelligence assignments and get sweet, delicious karma.

Edit: OK, I was a bit snarky, but I'm serious.

I see these things on HN all the time. These are, quite literally, undergraduate projects.

I don't see people upvoting "My First Stack" or "Check out this Pet Shop I wrote in J2EE". Computational intelligence is not some land of super wise geniuses that mere mortals cannot ascend to. It's all pretty straightforward.

Eg, my Ant Colony Optimiser for a Travelling Salesman Problem:

https://github.com/jchester/ruby-ry48p-aco

and my Genetic Algorithm for optimising Ackley's Function:

https://github.com/jchester/ruby-ackley-genetic-algorithm


> This makes me think I should upload my random computational intelligence assignments and get sweet, delicious karma.

Does karma matter that much to you?

> Edit: OK, I was a bit snarky, but I'm serious.

Well, what's stopping you? The fear of getting people to hate at you like this in comments? Really, you can do much better than this.

> I see these things on HN all the time. These are, quite literally, undergraduate projects.

They are people taking steps on the ladder to proficiency, as such they should be encouraged rather than be beaten down.

> I don't see people upvoting "My First Stack" or "Check out this Pet Shop I wrote in J2EE".

I don't see people submitting those either, which is one reason they're not being voted up. Once upon a time you too were a beginner. And in the eyes of many you probably still are.

> Computational intelligence is not some land of super wise geniuses that mere mortals cannot ascend to. It's all pretty straightforward.

Exactly! And what better way to demonstrate that by showing it, in a language that is generally despised.

> Eg, my Ant Colony Optimiser for a Travelling Salesman Problem:

> https://github.com/jchester/ruby-ry48p-aco

> and my Genetic Algorithm for optimising Ackley's Function:

> https://github.com/jchester/ruby-ackley-genetic-algorithm

That's pretty neat code ;)


> Does karma matter that much to you?

Revealed preferences suggest that it does :(

> That's pretty neat code ;)

Flattery will get you karma beyond your wildest dreams (for wildest dreams = 1).


> Flattery will get you karma beyond your wildest dreams (for wildest dreams = 1).

It's encouragement, not flattery.


Give the guy a little more credit.

Most Machine Learning/Neural Network code is in python or C/C++ not PHP. Something like this would be a good starting point if moving to Python is not an option.


A perceptron is

1. simple to code up

and

2. not very useful.[1]

You still need to pick the sort of neural network you're building (there are literally hundreds in the literature) before anything of consequence is going to happen.

The reason to use C/C++ libraries is that neural nets are slow. Slow slow slow. Computational intelligence / nature inspired computing is extremely cool, but the smart thing is to avoid it like the plague unless it is the only workable alternative.

[1] To the point that neural network research came to a screeching halt for some time when it was proved that a perceptron cannot perform a XOR on inputs.


>a perceptron cannot perform a XOR on inputs

Multi-layer perceptron networks, however, can.


Right. According to my old notes you need:

* at least one layer to handle linearly separable functions,

* at least one hidden layer to handle continuous functions, and

* at least two hidden layers to solve continuous and discontinuous functions.


Nice. Sort of the computational equivalent of 'A model of Neuschwannstein Castle made out of spaghetti'.


The code isn't all that bad, the spaghetti reference might give that impression.

PHP gets a bad rap because 'it's not a real language after all' but frankly I don't care what language you use if you write neat code like this that's an automatic 'pass'.

You can write spaghetti code in any language, but this isn't it.


I suspect that comment was more about the analogy of building detailed models out of pasta; in other words, that the subtext was that it looks like a painstaking technical feat achieved with strange materials for the purpose. And maybe in that respect all the more impressive.

PHP gets a bad rap because of problems with its design and implementation and some loosy-goosy culture (though most of these can be worked around or smoothed over by a framework and personal discipline, core language issues can be a form of technical debt). Really fixing this might require a breaking new version like Perl 6 or Python 3. But of course you can still build things with it. Like models of Neuschwannstein Castle ;)


That's pretty neatly written code!

If you've mastered PHP then you could easily make the switch to C or C++ for a very large speedboost while still being able to recycle a large chunk of your code. PHP and C look quite alike (drop the $ signs and add declarations and you're halfway there).

Neat to see you interested in doing more advanced stuff than just web bits and pieces.


Always nice to see these pet projects as proof of concept for ML in PHP. There's a bunch of them, but the more, the merrier.


I find it quite interesting how PHP developers try their best to encrypt their function names as much as possible? rdmFloat? Why not randomFloat or random_float?

This particular example isn't very problematic, but I see this pattern in PHP way more than in other languages.


Naming things is tricky. I got into programming when 6 character assembly labels were the norm. You can imagine what that led to. I still catch myself dropping vowels from function names every now and then (rndflt anybody?).

What's pretty good about this code is that it is neatly laid out, the modularity is just about right and it solves a particular problem and provides a bit of text showing how the bits get put together to make it work.

As such it beats a very large number of the github projects out there. Brevity in function names is easily forgiven when the code itself is this easy to read.

But I'm with you on the basic principle and I'd vote for random_float. iNeverCouldGetTheHangOfCamelcase.


Meh I see it in a lot of C++ code too. I don't understand it, especially from people who use an IDE so they shouldn't be typing those full names out anyway.


The guy didn't follow any of the accepted conventions, so please stop with the generalizations already.


Ha! You've triggered me to put my own PHP multi-layered neural network on GitHub. Available for forks & downloads here: https://github.com/infostreams/neural-network


ok whats the point? what can i train with this? what kind of outputs can i get?




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: