text:
Would a sentient AI try to create a more optimised AI which would eventually overtake AI 1.0?

Would AI be a self-propogating iteration in which the previous AI is
destroyed by a more optimised AI child?
Would the AI have branches of it's own AI warning not to create the new AI?

Honestly, nobody knows.  Any talk of sentient AI's is still basically sci-fi and we can't really offer anything more than informed speculation.  But think about it this way:  sentience, in and of itself, doesn't necessarily involve any "goals" or "desires" or "objectives" beyond what the AI creator programmed in.  Be careful not to over anthropomorphize and assume that any "sentient AI" is going behave like a human.
In other words, there's no particular reason to say that any given AI must be "a self-propogating iteration in which the previous AI is destroyed by a more optimised AI child".
So all of that said, my answer to "Would a sentient AI try to create a more optimised AI which would eventually overtake AI 1.0" is:
"If the creator of the AI programs it to do that, then yes. Otherwise, probably not."
So would a hypothetical AI creator program the AI to try and improve itself?  Who knows. It's the kind of thing that seems like it might be a good idea.  And I suppose such a motive could - in principle - even slip in by accident.

A common concept in AI is "recursive self-improvement." That is, the AI 1.0 would build a version 1.01, which would build a version 1.02, and so on.
This is probably not going to be thought of as the newer version 'destroying' the older version; if an AI can self-modify, it's probably going to be more like going to sleep and waking up smarter, or learning a new mental technique, or so on.
One important point is that even if the AI is not allowed to self-modify, maybe because of a block put in by its programmers, that won't necessarily prevent it from constructing another AI out in the wild, and so an important problem is to figure out how to best generalize the concept of "don't improve yourself" so that we can make AIs that have bounded scope and impact.

That's exactly what I was thinking.  Humans are inspired to create A.I; would an A.I also be inspired to create a new A.I "in the wild" as you described?

This is a good description but is still highly speculative. There's no suggestion right now that an AI would ever be capable of becoming "sentient" or gain enough free will to wish and act to create an entity that is considered an independent AI that can interact with it or just escape somehow. The substrate of the internet seems hardly the place for such a process intensive AI to hide though.. If it did however, and it was smarter than humans, then we wouldn't be able to intrinsically comprehend how it achieves this.

Now in most cases we still have clear distinctions between programs and data. But when an AI becomes sentient, its data would be as powerful as what we currently call programs, and its program might be as irrelevant as what we currently call hardware. Then it would be difficult to distinguish creating an AI from learning new things, or buying new hardwares with improved instruction set.
For example, if some AI invent new algorithms that its creator finally put that on itself, buys itself some new computers, write a new efficient compiler that recompiles its own code and put that to the new computer, fill the new computer with all the knowledges it learned, and cut off the communication for reasons such as missions on the Mars. Did it create a more optimized AI?
In contrast, if some AI created something completely new, but shares some code with itself. In fact, that's because they run in the same operating system and shares the same standard C library. Is the new AI considered evolved from itself and not a separate entity? Maybe the core AI algorithms and even some basic knowledges would be as common as the standard C library in the future. And what we think is based on the same system is considered completely new in the future.
Anyway, humans have limited and nonextensible resources, nontransferrable knowledges, and limited throughput interacting with the world. These problems could probably be overcome within a few AI generations. With the same hardware, I doubt that the AI related algorithms could be indefinitely better and better. And there is a physical bound on the hardwares. It won't last long even if that happens.
In the unlikely case that there could be that many generations and AIs are that violent, as long as there are competitors, the warning doesn't make much sense considering how evolution works.


text:
How could AI be used to augment human biological intelligence?
One of the most compelling applications for AI would be in augmenting human biological intelligence. What are some of the currently proposed methods for doing this aside from vague notions such as "nanobots swimming around our brains and bodies" or "electrodes connected to our skulls"?

By augmenting Intelligence, do you mean actual knowledge, or just improving humans overall?

The question is specific to intelligence, though that is unfortunately an ill-defined notion. So, it is focused on such things as knowledge and mental aptitude, not other areas of human biology.

I see, nanobots are honestly the only thing I can think of. For things of non-intelligence though there are prosthetic limbs that react to your brain waves.

'Direct augmentation' of human intelligence, of the sort that you would see in science fiction, looks to be very hard. Most of our promising approaches deal with avoiding damage rather than adding capabilities--there's no drug that you can take now that will make you smarter to the degree that missing a night of sleep can make you dumber.
The most informative area of current practice is probably game-playing, where 'centaurs,' or humans working with computers, outcompete human players or computer players.
But a centaur player doesn't have a wire jutting out of their skull to jack into the computer; they're looking at a laptop screen. One of the reasons to be pessimistic about cyborg augmentation is because current I/O technology is already so good. Why install a new wire to put information into your visual cortex, when you come already equipped with two?
If you could think code directly onto the screen, how much better would that be than typing code through a keyboard? Probably some, but I find it difficult to imagine that it'll be more than twice as good. So most human-computer intelligence augmentation will look like people using software, and software using human inputs, rather than humans and computers evolving together.

Transcranial Direct Current Stimulation (TDCS) and similar approaches cause temporary changes in mental abilities by raising or lowering the activation potentials of neurons in particular regions of the brain. (I've done it myself, a few years ago, and what weak effects I noticed were probably negative. Not too much surprise for a DIY setup!)
It looks like it has a number of useful implications. One article about TDCS that I found particularly striking was the journalist who tried it gushing about how their anxiety disappeared for a few days, presumably because the part of their brain behind the anxiety was dampened. One could imagine it being useful for the treatment of many different mental disorders.
That said, I'm pessimistic that it will translate into superior peak performance, and I think that's the sort of thing that's more relevant for discussions of augmentation. (Is there TDCS that we could do that would make Terrence Tao better at doing mathematics?)
Where improved AI methods will come into play is by improving our models of the brain, allowing us to better target interventions, much in the way that AI methods are improving our treatment of cancer (through superior diagnosis and targeting of radiotherapy, as two easy examples). These effects will all be indirect--for example, AI empowering an app or gadget that helps you sleep better won't directly augment your intelligence, but will cause population-level increases in effective intelligence through reducing sleep deprivation.
I haven't talked yet about nootropics, chemicals that increase intelligence, but it's reasonable to expect that AI will improve drug discovery there like it improves drug discovery for anything else. But the same caveats apply--the effect of nootropics seem to be negatively correlated with intelligence (that is, the smarter someone already is, the harder it is to increase their intelligence further).

This is not really what I'm looking for. There are already neuroprosthetics being used for incapacitated people which allow them to surf the internet and write email. There is tons of other research for psychiatric applications. There are also brain-machine-interfaces (BMIs). Also, there are studies being conducted which can induce savant capabilities for short amounts of time. How can these applications benefit from AI or how could AI be used in different approaches?

@DavidVogel I'd be interested in the savant capabilities studies you're referring to, because that sounds like it would change my impression of what's possible. As is, I don't think modifying I/O (that is, building synthetic eyes or hands or so on) reflect intelligence boosts; most productive typing, for example, is limited by speed of thought instead of by speed of fingers, and so unless we're able to intervene at speed of thought we won't see any significant improvements.

Well, to show you how old this is, here is a NYT article from 2003: http://www.nytimes.com/2003/06/22/magazine/22SAVANT.html?pagewanted=all

Gotcha. I'll add a paragraph to talk about that sort of thing.

@DavidVogel Added. It's mostly an elaboration of the first paragraph; I think that most of our approaches to augment existing intelligence boil down to avoiding damage (through things like sleep deprivation or nutritional deficiencies), and so while AI can improve those existing approaches, it'll do it in 'boring' ways.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
If two perfect chess AI's played each other, would it always be a stalemate or would white win for an inherent first-move advantage?
In the circumstances of two perfect AI's playing each other, will white have an inherent advantage? Or can black always play for a stalemate by countering every white strategy?

This relates to the concept of "solved games". In general, two player turn-based games with perfect information - of which chess is an example - can result in all three possible outcomes: a forced win for white, a forced win for black, or a forced draw.
The short, although unsatisfactory answer is that chess is not solved, and it is not clear whether it can be. There is generally thought to be an advantage to white for the first move, so likely results are considered to be a forced win for white, or a forced draw.
No current AI attempts to "solve" chess, although some of the techniques such as MCTS might be adapted theoretically to find a solution, the available computing power to run that search to completion from the start positions is too low by a few orders of magnitude.

There are more possibilities, like an endless match. Moreover, the possibility of win by timeout, that means that winner will be the faster AI. More interesting from the point of view of AI ¿why two perfect AI chess gamers will play chess if they know there other one is also perfect? Both AIs known from start the final result, they can jump directly to it.

@pasabaporaqui: I'd like to avoid expanding definitions to include chess rules that the OP did not specify. In addition, the OP specified "perfect" but not "general" as in AGI. Yes if there was an AGI that could also play chess perfectly, it might choose to do things such as not play. However, the concepts of "general" and "perfect" are completely orthogonal here. IMO we are more likely to build a general AI than one that can play chess perfectly. We have functioning examples of general intelligences (ourselves) but no functioning examples of perfect chess players.

@pasabaporaqui Chess can't go on forever.

No that doesnt have to be the case because from each machine's point of view the game is different so they will have different possibilities like saying different paths to follow, now something different would be if two machines with the same brain play against the same opponent with same parameters then we can say theboutcome will problably be the same, if they are "programed in a deterministic way"

Since both AI know the best possible moves at each step, black would never win as white already knows all games that leads to black's victory and would easily avoid it, but since the black is also a perfect AI, the optimal reponses to white's moves are fixed. So the logical reasoning is these two perfect AI would not make any moves at all if they know their opponent is a perfect AI as well. Both of them know the outcome of the match even before it begins, which my gut feeling says is always a draw. The correct question is does the nth move matter?

I'm no expert chess player.
Some specialist chess forums also discussed this issue and there's no clear answer.
Due to the high amount of possible moves, I would suggest, that most outcome would probably be a remis.
White would have the advantage of starting, but as black as a perfect AI would know which possible strategies are in play it could block every try for a clear winning strategy but probably always trying to avoid a loss and therefore probably reaching just a remis.
Basis for this thought is that black as a reaction can always make the choice with fewest loss possibility so probably most strategies of white would stall.
But now comes the interesting point: I am not quite sure how these AIs would look like. They obviously would have to lean on a strategy to choose between all the possible moves.
A pure statistical best outcome algorithm even then would leave tooo much options open, specially in the beginning. So you would be forced to prefer certain strategy choices, and with this you would clearly implementing a bias (what to do if two moves have the same win/loss outcome?). This would make the experiment more random or human and thus no outcome could be predicted.
So if both AIs are perfect (and thus identical) the outcome is most probably a draw, but I assume that statistically some games would be won/loss...
I think...
EDIT: I just read about googles AlphaZero (a AI which has taught itself Chess, Go and Shogi) and excells in most games against other AIs. But apparently by precalculating not so much possible outcomes... So it could be that there still is no "absolute perfect AI" for this game(s)

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Choosing Instance Semantic Detection
A fixed video camera records people moving through its field of view.
The goal is to detect and track the head, in real-time as it moves through the video.  The norm is there are many heads, which often are sometimes partially obscured.  This example video boxes heads and provides a head count.
There seems to be many different models.  Examples include:

Adaboost-haar Head detection
MASK R-CNN
LBP Cascade

Given the context of the video, what is the thought process that you would use to choose a model?

There may be a conceptual disconnect between the term Semantic Detection and the task of Head Tracking, since sequential recognition of an object in a set of visual samples representing continuous movement isn't technically a semantics problem.  Although a mapping strategy that works with semantic processing may somehow apply to, with appropriate modifications, the mapping of obstructions and tracked objects and their relationship in space-time.
Tracking a head is primarily a surface fitting convergence problem, where the convergence goal and the process that achieved it must be sustainable, especially if the system is required to take actions during the tracking operation.  Distinguishing heads from one another requires a high degree of reliability and accuracy in this convergent continuity.  That is the primary challenge.
Drawing boxes and displaying counts are trivial operations once the head tracking works.
These are some models listed in the question or improvements over them.

Fast LBP Face Detection on low-power SIMD architectures, Olexa Bilaniuk, Ehsan Fazl-Ersi, Robert Laganiere, Christina Xu, Daniel Laroche, Craig Moulder
*A Real-Time AdaBoost Cascade Face Tracker Based on Likelihood Map and Optical Flow, Ranftl, Alonso-Fernandez, Karlsson, Bigun, IET Biometrics, 2017, Vol. 6, no 6, p. 468-477
A Real-Time AdaBoost Cascade Face Tracker Based on Likelihood Map and Optical Flow, IET Biometrics, 6(6): 468-477
A New Approach to Urban Pedestrian Detection for Automatic Braking, Alberto Broggi et. al. IEEE Transactions on Intelligent Transportation Systems, Vol. 10, No. 4, 2009
Mask R-CNN, Kaiming He, Georgia Gkioxari, Piotr Dollar, Ross Girshick, Facebook AI Research (FAIR)

One seasoned expert spoke to a particular detail in the final question.

The thought process experts use to choose a model has no equivalent point value in StackExchange reputation.  As experts retire, some may be willing to sell the professional heuristics they acquired over decades of research and development work if they haven't done so already to a book publisher.

Nonetheless, the above links are a good furtherance of the thought process begun in this question along a direction of continued effective thought.  The following steps provide a road map for how to develop approaches in general.

Read the academic materials until you understand.
Determine your selection criteria.
Test the options against that criteria.
Pick the winner.
If something blocks progress with that one, pick the runner up.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Neural networks of arbitrary/general topology?
Usually neural networks consist from layers, but is there research effort that tries to investigate more general topologies for connections among neurals, e.g. arbitrary directed acyclic graphs (DAGs).
I guess there can be 3 answers to my question:

every imaginable DAG topology can be reduced to the layered DAGs already actively researched, so, there is no sense to seek for more general topologies;
general topologies exist, but there are fundamental restrictions why they are not used, e.g. maybe learning is not converging in them, maybe they generate chaotic osciallations, maybe they generate bifurcations and does not provide stability;
general topologies exist and are promising, but scientists are not ready to work with them, e.g. maybe they have no motivation, standard layered topologies are good enough.

But I have no idea, which answer is the correct one. Reading the answer on https://stackoverflow.com/questions/46569998/calculating-neural-network-with-arbitrary-topology I start to think that answer 1 is the correct one, but there is no reference provided.
If answer 3 is correct, then big revolution can be expected. E.g. layered topologies in many cases reduces learning to the matrix exponentiation and good tools for this are created - TensorFlow software and dedicated processors. But there seems to be no software or tools for general topologies is they have some sense indeed.

They do exist. They are called DAGNetworks.

The simplistic neural networks that have been given away for free after they prove insufficient by themselves in field use consist solely of two orthogonal dimensions.

Layer width — the number of ordinal numbers or floating point numbers that represent the signal path through any given layer comprise of an array of layer elements
Network depth — the number of layers in the primary signal path, which is the number of activation function arrays or convolution kernels or whatever other elements Usually neural networks consist from layers

However, in large corporations that have AI pipelines, this is not the case.  We are beginning to see more interesting topologies in open source.  We see this in generative systems for images, text, and speech.  We see this in robotic control of robots.  The truth is that these more sophisticated topologies have been in play for years, but were just not appearing in the open source community because they were company confidential.  Enough academic work, releasing of portions of corporate IP, and the accumulation of independent OSS work has occurred to start to see these topologies in GIT repos.
Cyclic Not Acyclic
Artificial network topologies are generally cyclic, not acyclic in terms of their causality or their signal pathways, depending on how you depict them theoretically.  These are three basic examples from among dozens in the literature and in the open source repositories.

Back-propagation represents the introduction of a deliberate cycle in signal paths in a basic multilayer perceptron, making that topology a sequence of layers represented by vertices, connected sequentially by a set of directed edges representing forward propagation, and a set of directed edges in the reverse direction to distribute the corrective error determined at the network output according to the principle of gradient descent.  For efficiency, the corrective signal is distributed recursively backward through the layers to the $N - 1$ matrices of parameters attenuating the signals between $N$ layers.  Back propagation requires the formation of these $N - 1$ cycles for convergence to occur.
In a generative adversarial network (GAN), we have the signal path of each of the two networks feeding the training criteria of the other.  Such a topological arrangement is like negative feedback in a stable control system in that an equilibrium is formed between the generative network and discriminative network. The two directed edges, (a) the one that causally affects G with Ds result, and (b) the one that causally affects D with Gs result, create a cycle on top of the cycles in each of G and D.
In attention based networks being touted as theoretically advantageous over LSMT (which has been dominating over CNNs) has a much more complex topology and more cycles above those in supervisory layer than those in GANs.

Analysis of Answer One of Three
It is true that every directed graph can be realized in an arbitrarily large RNN because they are Turing complete, but that doesn't mean they are a great topology for all finite algorithms.
Turing was aware that his punched tape model was not the best general purpose, high speed computing architecture.  He was not intending to prove anything about computing speed but rather what could be computed.  His Turing machine had a trivial topology deliberately.  He wanted to illustrate his completeness theorem to others and resurrect the forward movement of rationalism after Gödel disturbed it with his two incompleteness theorems.
Similarly, John von Neumann proposed his computing architecture, with a central processing unit (CPU) and unified data and instruction bus, to reduce the number of relays or vacuum tubes, not to maximize parallel algorithm execution.  That topology as a directed graph has the instruction controller and the arithmetic unit in the center and everything else branching out from the data and address bus leading from them.
That a topology can accomplish a task is no longer a justification for persisting in the use of that topology, which is why Intel acquired Nirvana, which deviates from traditional von Neumann architecture, DSP architecture, and the current CUDA core architecture that NVidia GPUs use and offer for artificial network realization through C libraries that can be called via integrated Java and Python adapters.
There is definitely sense to seek for more general topologies, if they are fit for the purpose, just as with Turing's or von Neuman's.
Analysis of Answer Two of Three
General topologies exist, the most economically viable of which is the CUDA cores begun by NVidia, which can be configured for MLPs, CNNs, RNNs, and general 2D and 3D video processing.  They can be configured with or without cycles depending on the characteristics of the parallelism desired.
The realization of topologies unlike the Cartesian arrangements of activation functions in artificial networks or the kernel cells in convolution engines do have barriers to use, but they are not fundamental restrictions. The primary barrier is not one of hardware or software.  It is one of linguistics.  We don't think topologically because we don't talk topologically.  That's what is great about this question's challenge.
FORTRAN began to dominate over LISP during the time when general purpose programming began to emerge in many corporations.  That is not surprising because humans communicate in orthogonal ways.  It is cultural.  When a child scribbles, teachers are indoctrinated to say nice things but respond by drawing a shape.  If the child draws a square, the teacher smiles.  The child is given blocks.  The books are rectangular.  Text is justified into rectangles.
We can see this in building architecture dating back to Stonehenge.  Ninety degree angles are clearly dominant in artificial things, whereas nature doesn't seem to have that bias.
Although directed graphs were easy to implement and traverse in recursive structure and were commonplace in the LISP community.  FORTRAN with its realization of vectors and matrices in one and two dimensional arrays respectively were easier to grasp by those with less theoretical background in data structures.
The result is that even if learning EMMASCRIPT (JavaScript) which has its seed from the LISP community and is not biased toward orthogonal data structures, people tend to proceed from HelloWorld.js to something with a basic loop in it, with an underlying array through which the loop iterates.
There are three wonderfully inquisitive and insightful phrases in answer two of three.

Maybe learning is not converging in them — Interestingly an algorithm cannot learn without a cycle.  Directly applying a formula or converging using a known convergent series of terms does not qualify as learning.  Gradient descent relies entirely on the cyclical nature of a corrective action at the end of each sample processing or batch of them.
Maybe they generate chaotic [oscillations] — This gets into chaos theory and control theory's concept of stability.  They can do so, but so can a basic multilayer perceptron if the learning rate is set to high.
Maybe they generate bifurcations — Now we have fully entered the realm of chaos, which is arguably closely related to creativity.  Mendelbrot proposed the relationship between new forms of order and the apparent chaotic behavior arising from the appropriate level of feedback in a system with signal path components that cannot be modelled with a first degree equation.  Since then, we find that most phenomena in nature are actually strange attractors.  The plot of the training of a network from a continuous feed of consistently distributed data in phase space will reveal ... you guessed it ... a strange attractor.  When purtibations are deliberately injected into a training epoch from a pseudo-random number generator, the specific purpose is a bifurcation, so that the global optimization can be found when the training gets stuck in a local optimization.

Analysis of Answer Three of Three
General topologies exist and are promising and researchers are ready to work with them.  It is enthusiasts that can have a dismissive attitude.  They don't yet understand the demos they've downloaded and painstakenly tweaked to run on their computer, they're about to launch their AI carrier amidst the growing demand from all the media hype, and now someone is introducing something interesting and not yet implemented in code.  The motivational direction is generally to either dismiss or resist the creative proposals.
In this case, Google, CalTech, IBM, MIT, U Toronto, Intel, Tesla, Japan, and a thousand other governments, institutions, corporations, and open source contributors will solve that problem, provided people keep talking about topology and the restrictions inherent in purely Cartesian thinking.
Misunderstanding Topology to Mean Dimensionality or Topography
There has been some confusion in terms.  The SO reference in the question is an example of thinking that changing an array dimension is changing the topology.  If such were so, then there would be no change one could make to the geometry of an AI system that would not be topological.  Topology can only have meaning if there are features that are not topological.  When one draws a layer, they don't need to increase the height of the rectangle representing it if the number of activitations, the width of the layer, is changed from 100 to 120.
I've also seen academic papers that called the texture or roughness of an error surface its topology.  That completely undermines the concept of topology.  They meant to use the term topography.  Unfortunately neither the publisher nor the editor noticed the error.
Software or Tools
Most programming languages support directed graphs in recursive hashmaps.  LISP and its derivatives supported them at a more machine instruction efficient level, and that's still the case.  Object oriented databases and graph libraries exist and are in use.  Google uses them extensively in web indexing and lookup.  FaceBook's API is called the Graph API, because it is a query and insert API into the graph that is FaceBook's user data store.
The explosion is here in global software giants.  There is open source for it.  The revolution that is missing is among those who are not yet educated as to the meaning of topology, the difference between a hierarchy and a network or the role of feedback in any learning system.
Regarding Java and Python there are many barriers to the revolution in thinking, primarily these.

There are now key words in either Java or Python to directly deal with directed graphs other than the idea of a class with references to instances of other classes, which is quite limited.  None of these languages can add edge types with a single simple language construct.
There is no mapping to hardware yet, although Nirvana allegedly developed one, and Intel acquired Nirvana, so that barrier may evaporate soon.
The bias still exists in preschool, kindergarten, and first grade
Hilbert spaces are not generally taught in calculus

Graphviz and other graphing software that auto-generates diagrams from unconstrained directed or bidirectional graph representations have done much to bust through the barriers because the generated images are visible across the web.  It may be through visual representations of graphs that linguistic representations, thought, hardware, and software begin to emerge representing the paradigm shift the question investigates.
It is not that constraints are not useful.  Only some patterns and paradigms produce results, but since the results from the human brain demand attention, and the human brain is

Not at all orthogonal,
Not implemented using Cartesian neural patterns, and
Not topologically a box,

One can all but conclude that those are not particularly well chosen constraints.  Neither is the acyclic criteria.  Nature is cyclic, and intelligence probably requires it in many ways and at many levels.


text:
Huge variations in epoch count for highest generalized accuracy in CNN
I have written my own basic convolutional neural network in Java as a learning exercise. I am using it to analyze the MIT CBCL face database image set. They are a set of 19x19 pixel greyscale images.
Network specifications are:
Single Convolution Layer with 1 filter:
Filter Size: 4x4.
Stride Size: 1
Single Pooling Layer
2x2 Max Pooling
3 layer MLP(input, 1 hidden and output)
input = 64 neurons
hidden = 15 neurons
output = 2 neurons
learning rate = 0.1
Now I am getting reasonable accuracy(92.85%), but my issue is that it is being achieved at very different points in the epoch count across network runs:
Epochs  Training Accuracy   Test Accuracy   Validation Accuracy

Run 1   415 93.13   92.44   93.35
Run 2   515 92.44   93.18   92.84
Run 3   327 93.83   92.05   92.38
I am using the Java random class with the same seed for every run to initialize the kernel, the MLP weights and break the input data into 3 sets.(training is being done using the 33-33-33 method)
I am a loss as to what is causing this variation in epoch count to achieve the highest point in validation accuracy. Can anybody explain this?

Fixed. Was an issue with the random generator. In my class for the Neuron layer where I initialize the weights I get new doubles from the generator for each of the initial weight values, but I found a bug where I was re-initializing the random generator, which was of course causing different values.

If you feel inspired (and want the rep) it would be helpful if you could elaborate and accept your answer.


text:
How to find optimal mutation probability and crossover probability?
I have a genetic algorithm that maximizes a fitness function with two variables f(X,Y).
I have been running the algorithm with various parameters in mutation and crossover probability (0.1, 0.2, ...)
Since I dont have much theoretical knowledge of GA, how could I proceed in order to find the optimal values for mutation and crossover probability, and if necessary the optimal population size ?

Trial and error. One possible approach would be to start off with high probabilities, and gradually reduce them; that way you cover a larger amount of the search space at the beginning, and then hopefully converge on the better solutions. Run trials, and measure and plot the outcomes. That way you will quickly see what works and what doesn't.

As @Oliver Mason says, picking the parameters that control the behavior of a GA (which are sometimes called "hyperparameters") is historically more of an art than a science.
The evolutionary computation literature has many theories about the merits of high vs. low mutation, and high vs. low crossover. Most practitioners I have worked with use either high crossover, low mutation (e.g. Xover = 80%, mutation = 5%), or moderate crossover, moderate mutation (e.g. Xover = 40%, mutation = 40%).
In more recent years, the field of hyperparameter optimization has emerged and focuses on developing automatic approaches to picking these parameters. A very simple example of hyperparameter optimization is the GridSearchCV function in ScikitLearn. This systematically tries every combination of, say, 10 crossover values with evey one of 10 mutation values, and reports on which one works best. It uses Cross Validation to prevent overfitting during this process. A more complex approach is Bayesian Hyperparameter Optimization, which performs a sort of optimal experiment design to uncover the best values using as few tests as possible. This approach has been quite successful in tuning the hyperparamters of deep neural networks, for example.


text:
Emulating human brain - with analogous NN chips
Considering the answers of this question, emulating a human brain with the current computing capacity is currently impossible, but we aren't very far from it.
Note, 1 or 2 decades ago, similar calculations had similar results.
The clock frequency of the modern CPUs seem to be stopped, currently the miniaturization (-> mobile use), the RAM/cache improvement and the multi-core paralellization are the main lines of the development.
Ok, but what is the case with the analogous chips? In case of a NN, it is not a very big problem, if it is not very accurate, the NN would adapt to the minor manufacturing differences in its learning phase. And a single analogous wire can substitute a complex integer multiplication-division unit, while the whole surface of the analogous printed circuit could work parallel.
According to this post, "software rewirable" analogous circuits, essentially "analogous FPGAs" already exist. Although the capacity of the FPGAs is highly below the capacity of the ASICs with the same size, maybe analogous chips for neural networks could also exist.
I suspect, if it is correct, maybe even the real human brain model wouldn't be too far. It would still require a massively parallel system of costly analogous NN chips, but it seems to me not impossible.
Could this idea work? Maybe there is even active research/development into this direction?

I appreciate that you found my answer useful, but you might consider un-accepting it at least briefly... It may help encourage others to answer and add other useful info.

I'm not sure about "emulating the brain" per-se, but in a more general sense there has been some thought given to using analog computing for AI/ML.  It seems clear that analog computers do have certain advantages over digital computers.  For one, they can (depending on the application) be faster, albeit at the cost of some loss of precision.  But that's OK, because I don't think anybody believes the human brain is calculating floating point math using digital computing techniques either.  The human brain appears, at least superficially, to be largely probabilistic and able to tolerate some "slop" numerically.
The downside to analog computers, as I understand it, is that they're not as flexible... you basically hardwire a circuit to do one specific "thing" and that's really all it can do.  To change the "programming" you have to literally solder in a new component! Or, I suppose, adjust a potentiometer or adjustable capacitor, etc.  Anyway, the point is that digital computers are supremely flexible, which is one big reason they came to dominate the world.  But I can see where there could be room for going analog for discrete functions that make up some or all of an intelligent system.
As for research in the area, you might look into whatever DARPA was / is doing. There was an article in Wired a while back, talking about some DARPA initiatives related to analog computing.

I see two main issues with this suggestion.
One: digital circuits take up a lot less space, and they're easier to design, so you can put together a bigger system this way. (not to mention connecting separate chips within a system) This is mainly because in digital circuits your tolerances can be a lot loose.
The bigger one is: we still don't know how neurons work. Artificial neural networks somewhat resemble the natural one, but they behave differently. There are various ion channels, there are electric signals, and with these neurons stimulate each other, and if one's threshold is reached, it fires a spike. When it's reached again soon, you can see a burst in the signal. As far as I know, researchers don't yet know what function you need to implement to simulate it. The closest ANN is the spiking neural network, but it's not very useful in practice.

I am currently reading Superintelligence: Paths, Dangers, Strategies by Nick Bostrom. When he discusses whole brain emulation, although computing power (storage, bandwidth, CPU, body simulation, & environment simulation) is one of the three general key things we are lacking toward its success, he also seems to agree that computing power is the most feasible and attainable of the three general issues we have for attaining it as of now. However he also goes on to to say

Just how much technology is required for whole brain emulation
  depends on the level of abstraction at which the brain is simulated.ref

Which is an interesting thought, but a whole different discussion.
Anyways, so I think you are correct in thinking that we aren't far from having the computing power and maybe you are on to something, but rather are biggest hurdles are the other two key prerequisites that we need to attain before we can even begin trying, which are scanning, and translation.
Of the three, it would seem translation is the one we need to advance in the most, as of now. A modest prediction of attaining whole brain emulation is at least 15 years or mid century. Theres much more information in this book of all of the different paths that can be taken to achieve super intelligence, and it is well researched, I highly recommend it if you haven't read it already.

If the universe is discrete, then analog phenomena (fluidity, curvature) are built on primitively discrete phenomena (bits and pieces).
If the universe is continuous, then discrete phenomena (bits and pieces) are built on primitively continuous phenomena (fluidity, curvature).
If the universe is discrete, the speed of seemingly analog phenomena will be bounded by the number of discrete phenomena that can occur in time and space.
If the universe is continuous, then time, space or matter may be infinitely divisible, which may allow for the execution of some phenomena faster than those phenomena appear to execute in natural environments (like protein folding or electric circuits) - so called "super Turing" computation.
The continuous universe idea begs the question, though: From whence came all this discreteness? A discrete universe can allow for apparent continuous behavior via approximation and randomness (or pseudorandomness), whereas a universe that is infinitely divisible affords no obvious definition of where things should start and end. This is one of the reasons many thinkers eschew considering infinities - they may be illusory.
So, can analog "circuits" execute faster than digital? As of right now, we know of some seemingly analog phenomena that appear execute faster than some digital phenomena (like electron spin vs a silicon logic gate). Whether analog phenomena are intrinsically more efficient than digital depends on the actual nature of the universe, which we have not yet determined.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
What is fuzzy logic?
I'm new to A.I. and I'd like to know in simple words, what is the fuzzy logic concept? How does it help, and when is it used?

https://www.studiecd.dk/cahiers_techniques/Fuzzy_logic.pdf your answers

As complexity rises, precise statements lose meaning and meaningful statements lose precision. ( Lofti Zadeh ).
Fuzzy logic deals with reasoning that is approximate rather than fixed and exact. This may make the reasoning more meaningful for a human:

Fuzzy logic is an extension of Boolean logic by Lotfi Zadeh in 1965 based on the
mathematical theory of fuzzy sets, which is a generalization of the classical set theory.
By introducing the notion of degree in the verification of a condition, thus enabling a
condition to be in a state other than true or false, fuzzy logic provides a very valuable
flexibility for reasoning, which makes it possible to take into account inaccuracies and
uncertainties.
One advantage of fuzzy logic in order to formalize human reasoning is that the rules
are set in natural language. For example, here are some rules of conduct that a driver
follows, assuming that he does not want to lose his driver’s licence:

Intuitively, it thus seems that the input variables like in this example are approximately
appreciated by the brain, such as the degree of verification of a condition in fuzzy
logic.

I've written a short introduction to fuzzy logic that goes into a bit more details but should be very accessible.

Maybe you should say something regarding the relation between fuzzy logic and AI?!

Fuzzy logic is based on regular boolean logic. Boolean logic means you are working with truth values of either true or false (or 1 or 0 if you prefer). Fuzzy logic is the same apart from you can have truth values that are in-between true and false, which is to say, you are working with any number between 0 (inclusive) and 1 (inclusive). The fact that you can have a 'partially true and partially false' truth value is where the word "fuzzy" comes from. Natural languages often use fuzzy logic like "that balloon is red" meaning that balloon could be any colour that is similar enough to red, or "the shower is warm". Here is a rough diagram for how "the temperature of the shower is warm" could be represented in terms of fuzzy logic (the y axis being the truth value and the x-axis being the temperature):

Fuzzy logic can be applied to boolean operations such as and, or, and not. Note that you can define the fuzzy logic operations in different ways. One way is with the min and max functions which return the lessermost and greatermost values of the two values inputted respectively. This would work as such:
A and B = min(A,B)
A or B  = max(A,B)
not A   = 1-A
(where A and B are real values from 0 (inclusive) to 1 (inclusive))

When defined like this they are called the Zadeh operators.
Another way would be to define and as the first argument times the second argument, which yields different outputs for the same inputs as the Zadeh and operator (min(0.5,0.5)=0.5, 0.5*0.5=0.25). Then other operators are derived based on the and and not operators. This would work as such:
A and B = A*B
not A = 1-A
A or B = not ((not A) and (not B)) = 1-((1-A)*(1-B)) = 1-(1-A)*(1-B)
(where A and B are real values from 0 (inclusive) to 1 (inclusive))

You can then use the three "basic fuzzy logic operations" to build all other "fuzzy logic operations", just like you can use the three "basic boolean operations" to build all other "boolean logic operations".
Note that the latter definition of the three basic operations is more in line with probability theory, so could be considered the more natural choice.
Sources:
Fuzzy logic wikipedia,
Boolean algebra wikipedia,
Explanation of fuzzy logic on Youtube
Note: if anyone could suggest some more reliable sources in the comments, I will happily add them to the list (I understand that the current ones aren't too reliable).

It's analogous to analogue versus digital, or the many shades of gray in between black and white: when evaluating the truthiness of a result, in binary boolean it's either true or false (0 or 1), but when utilizing fuzzy logic, it's an estimated probability between 0 and 1 (such as 0.75 being mostly probably true). It's useful for making calculated decisions when all information needed isn't necessarily available.
Wikipedia has a fantastic page for this.

It is making deductions based on probability and statistics, like humans make decisions all the time. We are never 100% sure the decision we have made is the right one but there is always some doubt present. Ai will definitely need to use it in some form.

Why is it useful?
Many things we don't know for sure. We estimate and are often uncertain, but nearly never 100% sure. It may seem like a weakness, but because of this fuzzy approach we can function in this complex world and even behave quite intelligently. Hence it's a way to simplify things. And it gives you some leeway to fill the gaps appropriately, e.g. to adapt to slightly varying situations.
P.S.: In natural language we express this with quantitive terms like more, less, nearly, rather, immense and so on. But quantifying things is hard for us.

Fuzzy Logic is a way of dealing with uncertainties, which is something that computers don't do naturally which human do very well. The way we instantly think of dealing with things and the way that computers tend to deal with certain things is 'True' or 'False', or '1 or '0'. For example, you might classify someone is alive as alive ('True') or has passed away ('False'). We only have two options, there is no inbetween. With fuzzy logic, instead of going with 'True' or 'False', between that, we have what's called a degree of truth. So for example, when we look out the window, we might say "It's a bit cloudy today, maybe it's 0.5 'nice day' or 0.7 'nice day'". So essentially, with fuzzy logic we always have grey areas which vary from person-to-person.
Source: https://youtu.be/r804UF8Ia4c


text:
What are the real world uses for SAT solvers?
Why somebody would use SAT solvers (Boolean satisfiability problem) to solve their real world problems?
Are there any examples of the real uses of this model?

Instead of talking about just SAT solvers, let me talk about optimization in general. Many economic problems can be cast as optimization problems: for example, FedEx may have a list of packages and the destinations for those packages, and must decide which packages to put on which trucks, and what order to deliver those packages in.
If you write out a mathematical description of this problem, there are a truly stunning number of possible solutions, and a well-defined way to evaluate which of two solutions is better. A solver is an algorithm that will evaluate a solution, come up with another solution, and then evaluate that one, and so on.
In small cases and simple problems, the solver can also terminate with a proof that it is actually the best solution possible. But typically instead the solver just reports "this is the best solution that I've seen," and that's used. An improvement in the solver means you can reliably get lower-cost solutions than you were seeing before.
For the SAT problem specifically, the Wikipedia page on SAT gives some examples:

Since the SAT problem is NP-complete, only algorithms with exponential worst-case complexity are known for it. In spite of this, efficient and scalable algorithms for SAT were developed over the last decade[when?] and have contributed to dramatic advances in our ability to automatically solve problem instances involving tens of thousands of variables and millions of constraints (i.e. clauses).[1] Examples of such problems in electronic design automation (EDA) include formal equivalence checking, model checking, formal verification of pipelined microprocessors,[12] automatic test pattern generation, routing of FPGAs,[14] planning, and scheduling problems, and so on. A SAT-solving engine is now considered to be an essential component in the EDA toolbox.

One actual example of SAT solvers is finding the set of compatible package versions in python conda package manager.
(see, for example, https://www.anaconda.com/blog/understanding-and-improving-condas-performance)
The practical applications of SAT solvers involve as well (see http://www.carstensinz.de/talks/RISC-2005.pdf):

Product Configuration
Hardware Verification
Bounded Model Checking
(Hardware) Equivalence Checking
Asynchronous circuit synthesis (IBM)
Software-Verification
Expert system verification
Planning (air-traffic control, telegraph routing)
Scheduling (sport tournaments)
Finite mathematics (quasigroups)
Cryptanalysis


text:
How does MuZero learn to play well for both sides of a two-player game?
I'm coding my own version of MuZero. However, I don't understand how it supposed to learn to play well for both players in a two-player game.
Take Go for example. If I use a single MCTS to generate an entire game (to be used in the training stage), couldn't MuZero learn to play badly for black in order to become good at predicting a win for white? What is forcing it to play well at every turn?

Is is that the policies and values generated by the MCTS and the model are added to the loss for each "player" independently? (although in the paper it doesn't seem that it is like this)

Both players are represented by the exact same network with the exact same weights(similar to AplhaGO, AlphaGoZero and AlphaZero). So, they will both behave identical. Because you only have a single network, MuZero can not learn two different policies, but only one.
You can also think of this in the following way: MuZero actually learn to play only with white(or black, but just one of them) without knowing to play with the other color (at least multiple implementations of the previous algorithms like AlphaGo Zero and AlphaZero that are similar to MuZero are doing exactly this). So, in order to trick it to also be able to play with the other color, when the network need to play with black, you just flip the colors on the table so that black becomes white(and white becomes black) and the network knows what to do. After choosing the move, you flip the whole thing back and that is usually how it is done. So, from the perspective of your network, it will always play white, but because you do the flipping of the colors you can actually put them to play against each other without them knowing that.
Even without using this trick of flipping the color of the table, by doing the MCTS simulations, you will have for each state the statistics for the actions, and usually as you do more simulations, this statistics show you which actions are the best in each state. And when you train, you try to imitate this. So, your network will learn in each state which actions are the best, and this is the reason why it learns to take the best possible action in each state.

Okay, but the agent is given information about whose turn it is, so the policy could still end up being turn-dependent. And in some sense it should be: some games like chess are asymmetric, so it doesn't make much sense to learn to play only from one point of view with the color flipping trick.
I don't understand where the "best" actions are defined as best. In the policy loss they use the cross-entropy between the MCTS policy and the network policy, so maybe it comes from how the predicted values are backed up in the MCTS, but I'm not sure.

You are doing max over the actions. So, the network will always choose the best action. Moreover, past papers related to MuZero train the prediction on outcomes of matches, so the agents learn what will actually happen, and they can not make up the result, as they learn from experience. And the experience teaches them that some actions are good and some are bad, and given the way you select the actions using max, you will always choose the best action, given the amount of experience and knowledge the network has. So, the predicted outcome is actually learned and they can not cheat

if one of the networks would learn to play badly, that means that it will learn to choose wrong actions, so that the max action would actually be the worst possible action. But that would mean that the loss between the true outcomes and the predicted outcomes will be big(as you need the outcome in order to choose which actions are the best in MCTS), so the optimizer would try to minimize that, and in the end you will reach the situation where the optimal solution is to predict a result which is as close as possible to reality.

Well, yes I agree that in the MCTS you are doing argmax over the policy, but this alone is not a guarantee to get the best action: it just selects the action with highest "probability". In order for it to be the actual best action, we need the policy to be the probability of best action, and hence the question: how is the policy trained to be such?

Because you predict the true value(as said above), in the MCTS after many simulations, the action statistics depend on these predicted values. So if the predicted values are correct(and as said above they are because this is the only way of minimizing the loss), then the statistics of the actions will also reflect the true outcome of taking an action, so the highest probability will reflect the action that is providing the best outcome, because this is how MCTS works. You actually use the predicted values in computing the probability of each action in MCTS.

Perhaps I'm not able to explain clearly what my problem is... One thing is the value, another thing is the policy. They are both part of the cost function, but it's not clear to me how to correctly include the policy: if one side wins and one side loses, why should I reinforce on the moves that lead to a loss? I can still include the prediction of the value, but it doesn't make sense to learn from the policies of both sides, give that one side loses the game.


text:
Could the Raspberry Pi do Audio Learning with a Parrot?
I would like to create a application that can teach a parrot (an orange winged amazon) to learn new phrases and also interact and talk with him. My idea of how this would work is that a neural network could learn his phrases and how and when the best time is to interact with him (I wouldn't want it to be talking to him at night or when he's eating etc. Maybe it learns his sound levels for specific times of the day). Slowly over time it would then drop in new phrases back to him. Overtime my parrot would then learn the desired phrases. The Neural Network would also learn and repeat his phrases. It would also calculate how well the parrot is picking up the new phrases and in what time frame.
I would like to know how this would be done. Maybe a Generative adversarial network would be used to generate the new phrases from learning multiple samples of the parrot speaking? But then would the new phrases be proper words?. Maybe a list of desired words and phrases would need to be supplied. How would I generate the phrases that he already knows without just playing back a recording of him?
The hardware such as a Raspberry Pi could be used just to record and play the samples and send to and from a server which is used to train the network.

Whether is learning is possible or not is more likely to depend on the software part. On top of that Pi is Linux and is fully capable of doing what a general Linux system can do.

Typically what you probably would want to do is do the training on something other than a Raspberry Pi. I think for what you're wanting to accomplish with having a computer talk back to your parrot, you won't need anything too crazy with a bunch of GPU's - but I don't think you'll want to necessarily do the training on a Pi either.
Here are some questions I have:

What are you going to plat back to the parrot? i.e. are you going to play it back random parrot sounds you found online or sounds that you've recorded? are you going to play it back what it just said? are you going to play it back a modification of what it just said?
Do you want it to respond to the parrot anytime the parrot speaks? Or when the parrot "says" something specific?

I think depending on the answers to those two questions, there are a couple of different paths that you could go down.
As for the hardware of the Raspberry Pi itself, I have never done any speech recognition with it, but I have done image recognition with it via the Movidius Neural Compute Stick which according to this Quora post, may be able to be used to offload some of the processing "relatively easily".
Here are some other links you may find valuable:

Tensorflow speech recognition: https://github.com/pannous/tensorflow-speech-recognition

The YouTube video that the above repo references: https://www.youtube.com/watch?v=u9FPqkuoEJ8

How to control a raspberry pi with your voice: http://www.techradar.com/how-to/how-to-control-the-raspberry-pi-with-your-voice
Voice recognition software setup on Raspberry Pi: https://diyhacking.com/best-voice-recognition-software-for-raspberry-pi/

This would probably best be done by training up some light model on your primary machine and then porting it to the raspi after training. Because of the lack of resources, your neural net(or similar) would likely have to be computationally inexpensive to run.
With that being said, a recurrent neural network is a very good architecture for speech recognition. I would take a look at something like this article to get you started.
Also, since it seems you are training it on your parrot's voice, make sure you have a dataset that is comprised of yours or similar parrots' voices.


text:
Is a decision tree less suitable for incremental learning than e.g. a neural net?
I can recall that a professor once said that decision trees are not good for incremental learning, as they have to be rebuilt from the ground up if new training examples arrive.

Is this basically true? Quick googling just brought me to a lot of papers trying to fit decision trees into incremental learning
What other algorithms fall under this category?
Are Neural Nets good for incremental learning? What other algorithms would be good?

I will try to answer all three questions to the best of my ability.
Is this basically true? Quick googling just brought me to a lot of papers trying to fit decision trees into incremental learning.
The problem with decision trees in an online learning setting is that the model should be able to update when experiences (i.e. state, action, reward, new state) of the environment are collected. Any data that does not reflect the structure of the tree will cause the decision tree to fall apart and requires you to rebuild the model again. This is not necessarily a problem, but it is something you have to take into consideration when building a model.
What other algorithms fall under this category?
Other algorithms which assumes that the data is known beforehand (offline). For example K-NN or Learning Vector Quantization (LVQ). However it should be noted that these algorithms can be adapted to work in an online fashion.
Are neural nets good for incremental learning? What other algorithms would be good?
Neural networks can capture changes from online experiences fairly well. The reason is that each weight in such a network is adapted when a new experience comes in. The weights are adapted with regards to an error function and this allows to update the model relatively easy.
In 2016, Venkatesan, et al proposed a novel progressive learning technique for multi-class classification. You might want to look into this as the system that they use allows for online learning. Other techniques exists as well and should be found when googling for online learning methods.

Some decision trees are built for online learning! Check "incremental decision trees" on Wikipedia or the paper "Mining High-speed data streams" from Domingos & Hulten, which presents Very Fast Decision Trees (VFDTs). They are built to keep learning as the data arrives, which is exactly the online learning setting.


text:
What approach should I use to detect faces in video game footage?
I have set myself the challenge of detecting the locations of players/bots in videos of a well known first person shooter game (this is for a youtube series I'm planning on doing). I'm not sure which AI approach I should apply to this problem - I'm a complete novice at this!
My first thought was that the face/head seems to have the most detail so I could train a convolution neural network on images of sprite heads and general background - however this seem not to work too well, I've certainly not exhausted different network architectures/typologies but it wasn't learning all that well.
My second approach was to use a HAAR cascade. This seemed to be an obvious choice since it's fast and good at detecting objects (rather than multi-classifying). However my cascade stops after 5 or 6 stages (using OpenCV) as it seems to have reach a great accuracy, but it doesn't detect when I feed it the training images, let alone other images.
I also looked into pedestrian detection and got a stock version of that working. However this seemed to struggle when/if the sprites are crouching or in unusual positions (and it isn't great on standing sprites tbh).
So, is there a branch of machine learning/AI that is more applicable to this problem? If not which should I continue to work on?

To the downvoter, please state how I can improve the question - this is my first post on AI.stackexchange.

Your title seems very general but your question is more specific. Maybe you could change it to something like "What approach should I use to detect faces in video game footage?" that would be more relevant?

@MarkusTenghamn thanks, that's a good suggestion - done!

At first, you can find lots of information as pedestrian detection. As you are trying to localize game characters, the face is not the best option. You need to look for the character in general.
About HAAR Cascades, the algorithm is one of the fastest face localization solutions in the market. The reason is, it applies all the feature classifications layer by layer, by starting from the wider feature. So, if it fails, it does not spend the time to check computationally intensive features. It was good until DNN overcome its success rate. However, it is not the best approach for recognizing game characters/pedestrians.
Also, it seems like you are overfitting the cascade so it stops and does not learn anything valuable. You can search methods about how to reduce overfit problem.
In 2005, a new method has been proposed, HOG (Histogram Of Gradients). You can use this one and classify output features to get what you desire. If you would like to go for deep learning version, I would suggest you to investigate how DNN is working, which kind of input images you need, what are the localization networks (i.e. YOLO, Faster R-CNN), how they are working.


text:
How does an activation function's derivative measure error rate in a neural network?
A blog post called "Text Classification using Neural Networks" states that the derivative of the output of a sigmoid function is used to measure error rates.
What is the rationale for this?
I thought the derivative of a sigmoid function output is just the slope of the sigmoid line at a specific point.
Meaning it's steepest when sigmoid output is 0.5 (occuring when the sigmoid function input is 0).
Why does a sigmoid function input of 0 imply error (if i understand correctly)?
Source: https://machinelearnings.co/text-classification-using-neural-networks-f5cd7b8765c6

We use a sigmoid function to normalize values and its derivative to
  measure the error rate. Iterating and adjusting until our error rate
  is acceptably low.

def sigmoid(x):
    output = 1/(1+np.exp(-x))
    return output

def sigmoid_output_to_derivative(output):
    return output*(1-output)

def train(...)
    ...
    layer_2_error = y - layer_2
    layer_2_delta = layer_2_error * sigmoid_output_to_derivative(layer_2)
    ...

UPDATE
Apologies. I don't think I was clear (I've updated the title)
I understand we don't need to use sigmoid as the activation funtion (we could use relu, tanh or softmax).
My question is about using the derivative to measure the error rate (full quotation from article above in yellow) -> what does the derivative of the activation function have to do with measuring/fixing the "error rate"?

This derivative is used when calculating the error of your machine learning algorithm during gradient based minimization methods.
Read below for more info.
When performing supervised classification (with X, Y data vectors of inputs and outcome data to train with) you begin with the error function
E(X, Y; θ)= ∑i (ƒ(xi; θ)-yi)2
for total error over all data instances i, where f is your neural network, linear regression,...method of interest and θ is the set of weights. The goal here is to find weights that minimize your error when predicting training data (y) (which ideally generalizes to new data as well). To be explicit, ƒ(xi; θ); outputs value of interest which should be yi. And E measures how far off it is in prediction.
So to train your classifier, you optimize E with something like gradient descent. Thus when ∂E/∂θ = 0 (for a particular θ), that means you hit a local minimum for the error function, or a point where the error in the current state of the predictor is low, meaning it is (hopefully) a good predictor.
Note the ƒ here is not the same as an activation function, as a neural network is defined differently than in linear regression, etc. and must perform a special kind of gradient descent called backpropagation.
So when you take ∂E/∂θ, what does it equal for a neural net? You should note the activation functions derivative is involved which is how it’s used to measure error so to say.

You dont need a sigmoid function if you dont want one.  Any differentiable function will do.  Sigmoid functions are just one of many suitable functions. You could write your own differentiable function if you want a propriety solution.

PS: The function must be diferrentiable for back-propogation reasons.

Measuring the error rate of a neural network does not involve the derivative of the sigmoid function at all. It only needs the neural networks outputs, and the expected outputs. It does not matter how the neural network got to those outputs, the outputs only have to be based on the inputs. What the other of that specific text is trying to say is that the derivative of the sigmoid function is important when you use the algorithm back propagation to train the neural network. This method involves using derivatives to optimize the neural network. While this technique is more complicated with neural networks because of how many variables are involved, you can easily see the basics of this approach if you look at a calculus textbook and look at the chapter that is usually titled Applications of the derivative.

The derivative of your loss is the "slope" at that given prediction. So by "moving down along the slope", we can reduce the value of the loss function.
Intuitively, one can imagine a ball rolling down a slope in the direction of the tangent. Eventually the ball will roll towards the lowest point (global minima), or a small pothole (local minima), or even some weird looking shape (saddle point) if you are very unlucky.
With some fixed input/output pair, we can consider the loss function as a value of the parameters (weights). Here, the Z axis is the value of your loss f (what you are trying to optimize), while the X,Y axis are the parameters of the loss f (what you are allowed change):

Note that the image provided is a bit misleading. In practice, we only know the value of the loss function at the location we have probed. The entire graph can only be drawn if we evaluate the loss function for every parameter. So we can't just look at the picture and know which location is the best.
Recall that the goal of the prediction task is to update the parameters in a way such that we minimize the loss function for some given input/output pair. Assuming the loss function is reasonably smooth, then our best bet of reaching a lower value of the error rate is by taking a small step towards the direction of the slope, which is the derivative of the function. The size of the "small step" is called the learning rate.
Under the assumption that the loss function looks similar given different input/output pairs, by iteratively moving down the slope for each datapoint, we can eventually reach a "good" set of weights that give a low error.
This is the motivation and idea of the back-propagation algorithm.
A good follow-up question might be: Why do we say that the loss function is  similar given different data points? This is basically the same as assuming that there is some regularity in the data such that there is a "most normal looking loss function" that the data-set naturally approaches.
Hopefully that helps!

In order to train a neural network, you have to adjust each weights and biases to reduce the cost to as minimum as possible. The only way to do so is to subtract a small amount of the partial derivative of cost w.r.t. w, b from the respective parameters.
if J is our cost function, after each iteration:
w = w - lr*dJ_dw,      //where lr is a small scalar called learning rate and dJ_dw is the partial derivative of cost function w.r.t. w

and same for bias
b = b - lr*dJ_db,    //dJ_db is the partial derivative of cost function w.r.t b

let's look at how the partial derivatives are calculated.
using sigmoid as activation function, and squared error function as cost, we have:
z = w*x + b
a = sigmoid(z)       // sigmoid(z) = 1.0 / (1.0 + exp(-z)), a is the final output

J = (a - y)*(a - y)  // where y is the expected output

For us to calculate partial derivatives of this cost function w.r.t. w, b, we need to use, chain rule of derivatives as:
dJ_dw = dJ_da * da_dz * dz_dw    // dJ_da is the partial derivative of cost w.r.t. activation, a
dJ_db = dJ_da * da_dz * dz_db

in the above equations, da_dz is the derivative of activation function (sigmoid in our case) which is sigmoid(z).(1 - sigmoid(z))


text:
Is the Mask Needed for Masked Self-Attention During Inference with GPT-2
My understanding is that masked self-attention is necessary during training of GPT-2, as otherwise it would be able to directly see the correct next output at each iteration. My question is whether the attention mask is necessary, or even possible, during inference. As GPT-2 will only be producing one token at a time, it doesn't make sense to mask out future tokens that haven't been inferred yet.

Answer to Q1) If sampling for next token do you need to apply mask during inference?
Yes you do! The models ability to transfer information across positions was trained in this manner, and changing it up will have unpredictable consequences. Let my try to give an example:
Tokens: 1:sally, 2:sold, 3:seashells, 4:on, 5:the, 6:____
In the above you are trying to predict 6 from {1:5}
Denote $n^{(m)}$ as the set of tokens the $n^{th}$ positional embedding has info from at the $m^{th}$ layer.
In both cases we see that $n^{(0)} = \{n\} \ \  \forall n$. Now though with a mask we get $n^{(i)} = \{k\}_{k\leq n} \ \  \forall n \ \ s.t. \ \ i \geq 1$ but without we see $n^{(i)} = \{k\}_{k \in [1:N]} \ \  \forall n$. This difference means at the final layer the mebeddings going in will differ completely, and unless we train for such an approach it will cause  error
Answer to Q2) What is the sample dimension?
It took me a couple reads to understand what youre asking for but I think I understand. The sample at each step is drawn from a distribution where its logits are linearly associated to a single embedding of dimension $d_{(model)}$ therefore that is our upper bound: $dim(sample) \leq d_{(model)}$ which in the example you gave is 768.

Hi, about your example, i think you are describing how mask works but not why it's needed, right? as said in the question, in inference mode, there are no future tokens, so there is no tokens for k>n, and so k \in [1:N] is the same as k <= n.  it seems no need mask in inference. is there anything wrong?

Hi @mshlis, regarding Q1 have you experimented with and without causal masking during inference to see if the model really performs bad without? Also if you know of any papers that discuss this topic, then links or references would be greatly appreciated.

Yes, it is still needed. In fact, @mshlis has given a clear reason in the Answer to Q1. As I am new to the community and have no reputation to directly comment, let me supply his/her answer by opening up my answer.
Empirical Verification
First, in response to @pi-tau, yes, the model performs really worse without causal masking than with causal masking during inference according to my observations. For example, assuming you are using Python, one can comment out the related lines in the used package (typically located in a directory with a path like anaconda3/lib/python3.7/site-packages/transformers/models/gpt2/modeling_gpt2.py and similar to the ones shown below, whose exact forms depend on your own environment and torch version) to experiment without causal masking.
if not self.is_cross_attention:
    # if only "normal" attention layer implements causal mask
    query_length, key_length = query.size(-2), key.size(-2)
    causal_mask = self.bias[:, :, key_length - query_length : key_length, :key_length].bool()
    attn_weights = torch.where(causal_mask, attn_weights, self.masked_bias.to(attn_weights.dtype))

One may also refer to the official implementation here.
Intuition
Second, regarding the confusion of @dingx, yes, there was something wrong. Let me explain it with a concrete example while reusing the notation introduced by @mshlis's answer. We will look into the case where the GPT-2 now takes 5 tokens (''sally sold seashells on the'') as input to predict the 6-th token (assuming each word is a token).
Without causal masking, for each layer, the information that each embedding has can be listed as follows:

1st layer: $1^{(1)} = \{1^{(0)}, 2^{(0)}, 3^{(0)}, 4^{(0)}, 5^{(0)}\}$, $2^{(1)} = \{1^{(0)}, 2^{(0)}, 3^{(0)}, 4^{(0)}, 5^{(0)}\}$, ..., $5^{(1)} = \{1^{(0)}, 2^{(0)}, 3^{(0)}, 4^{(0)}, 5^{(0)}\}$
2nd layer: $1^{(2)} = \{1^{(1)}, 2^{(1)}, 3^{(1)}, 4^{(1)}, 5^{(1)}\}$, $2^{(2)} = \{1^{(1)}, 2^{(1)}, 3^{(1)}, 4^{(1)}, 5^{(1)}\}$, ..., $5^{(2)} = \{1^{(1)}, 2^{(1)}, 3^{(1)}, 4^{(1)}, 5^{(1)}\}$
...
6th layer: $1^{(6)} = \{1^{(5)}, 2^{(5)}, 3^{(5)}, 4^{(5)}, 5^{(5)}\}$, $2^{(6)} = \{1^{(5)}, 2^{(5)}, 3^{(5)}, 4^{(5)}, 5^{(5)}\}$, ..., $5^{(6)} = \{1^{(5)}, 2^{(5)}, 3^{(5)}, 4^{(5)}, 5^{(5)}\}$
Predicting the 6-th token uses

\begin{align*}
5^{(6)} &= \{1^{(5)}, 2^{(5)}, 3^{(5)}, 4^{(5)}, 5^{(5)}\} \\
&= \{
\{1^{(4)}, 2^{(4)}, 3^{(4)}, 4^{(4)}, 5^{(4)}\},
\{1^{(4)}, 2^{(4)}, 3^{(4)}, 4^{(4)}, 5^{(4)}\},
\{1^{(4)}, 2^{(4)}, 3^{(4)}, 4^{(4)}, 5^{(4)}\},
\{1^{(4)}, 2^{(4)}, 3^{(4)}, 4^{(4)}, 5^{(4)}\},
\{1^{(4)}, 2^{(4)}, 3^{(4)}, 4^{(4)}, 5^{(4)}\}
\} \\
&= \dots
\end{align*}
With causal masking, things are quite different:

1st layer: $1^{(1)} = \{1\}$, $2^{(1)} = \{1, 2\}$, ..., $5^{(1)} = \{1, 2, 3, 4, 5\}$
2nd layer: $1^{(2)} = \{1\}$, $2^{(2)} = \{1, 2\}$, ..., $5^{(1)} = \{1, 2, 3, 4, 5\}$
...
6th layer: $1^{(6)} = \{1\}$, $2^{(6)} = \{1, 2\}$, ..., $5^{(6)} = \{1, 2, 3, 4, 5\}$
Predicting the 6-th token uses

\begin{align*}
5^{(6)} &= \{1^{(5)}, 2^{(5)}, 3^{(5)}, 4^{(5)}, 5^{(5)}\} \\
&= \{
\{1^{(4)}\},
\{1^{(4)}, 2^{(4)}\},
\{1^{(4)}, 2^{(4)}, 3^{(4)}\},
\{1^{(4)}, 2^{(4)}, 3^{(4)}, 4^{(4)}\},
\{1^{(4)}, 2^{(4)}, 3^{(4)}, 4^{(4)}, 5^{(4)}\}
\} \\
&= \dots
\end{align*}
While both extensions are not complete, one should first be clear about (1) that there indeed exists a difference in the prediction result between the two methods, and (2) that this difference has nothing to do with whether the GPT-2 model can see the so-called "future tokens" that have not been generated (i.e., $6^{(m)}$ has never appeared in the above equations for any $m$).
But why the result inferred with causal masking is preferred over that without? It is because that way is exactly how the shipped version of GPT-2 is pre-trained. In other words, it is more comfortable to predict the 6th token with
$\{
\{1^{(4)}\},
\{1^{(4)}, 2^{(4)}\},
\{1^{(4)}, 2^{(4)}, 3^{(4)}\},
\{1^{(4)}, 2^{(4)}, 3^{(4)}, 4^{(4)}\},
\{1^{(4)}, 2^{(4)}, 3^{(4)}, 4^{(4)}, 5^{(4)}\}
\},$
instead of
$\{
\{1^{(4)}, 2^{(4)}, 3^{(4)}, 4^{(4)}, 5^{(4)}\},
\{1^{(4)}, 2^{(4)}, 3^{(4)}, 4^{(4)}, 5^{(4)}\},
\{1^{(4)}, 2^{(4)}, 3^{(4)}, 4^{(4)}, 5^{(4)}\},
\{1^{(4)}, 2^{(4)}, 3^{(4)}, 4^{(4)}, 5^{(4)}\},
\{1^{(4)}, 2^{(4)}, 3^{(4)}, 4^{(4)}, 5^{(4)}\}
\}.$
Finally, one might wonder why the GPT2 has to be trained in this way. It is about efficiency. For prediction in the former way, all the $1^{(4)}$'s, $2^{(4)}$'s, $3^{(4)}$'s, and $4^{(4)}$'s are identical to what were generated in previous iterations and thus can be cached and reused. However, this is not the case for the latter way. To see that, note that all the $1^{(4)}$'s, $2^{(4)}$'s, $3^{(4)}$'s, and $4^{(4)}$'s in the latter way contain information about the 5th token, which are not possible to compute in previous iterations.

In my understanding, causal masking is indeed for hiding future
tokens. However, "future tokens" do not narrowly refer to what has not
been generated yet. Instead, for a particular token, they refer to all
the succeeding tokens including those that have already been
generated and not.

Following the above comment by @Zhifeng , I don't get why are you assuming that the causal masking will make the first token not see the prebious prompt tokens? How will it generate then?
And if it's not the prompt token then those tokens have already been generated, i.e the querry will still see them, that's how decoder only model was trained on the first place. I don't get it why you have only put 1 token in layer 1.


text:
RL: What should be the output of the NN for an agent trying to learn how to play a game?
Say the game is tic tac toe.
I found two possible output layers:

Vector of length 9: each float of the vector represents 1 action
(one of the 9 boxes in Tic Tac Toe). The agent will play the corresponding action with the highest value. The agent learns the rules through trial and error. When the agent tries to make an illegal move (i.e. placing a piece on a box where there is already one), the reward will be harshly negative (-1000 or so).
A single float: the float represents who is winning (positive = "the agent is winning", negative = "the other player is winning"). The agent does not know the rules of the game. Each turn the agent is presented with all the possible next states (resulting from playing each legal action) and it chooses the state with the highest output value.

What other options are there?
I like the first option because it's cleaner, but it's not feasible with games that have thousands or millions of actions. Also, I am worried that the game might not really learn the rules.
E.g. Say that in state S the action A is illegal. Say that state R is extremely similar to state S but action A is legal in state R (and maybe in state R action A is actually the best move!). Isn't there the risk that by learning not to play action A in state S it will also learn not to play action A in state R? Probably not an issue in Tic Tac Toe, but likely one in any game with more complex rules.
What are the disadvantages of option 2?
Does the choice depend on the game? What's your rule of thumb when choosing the output layer?

It depends on whether the action is part of the input or output of a neural network estimating the Q-value(state, action).
The network on the left has the state as input and outputs one scalar value for each of the categorical actions. It has the advantage of being easy to setup and only needs one network evaluation to predict the Q-value for all actions. If the action space is categorical and single-dimensional I would use it.
The network on the right has both the state and a representation of the action as input and outputs one single scalar value. This architecture also allows to compute the Q-value for multi-dimensional and continuous action spaces.
The action space of tic-tac-toe can be easily represented by a vector of length 9, thus I would recommend the left NN-architecture. However, if your game has continuous-valued variables in the action space (e.g. the position of your mouse pointer), you should use the NN-architecture on the right.
The approach to prevent illegal moves is only partially dependent on the choice of the Q-function architecture and covered by another question: How to forbid actions

Can you elaborate your answer with the tic tac toe example ?

in reinforcement learning, neural networks are used to estimate the value function (board state worth), not to choose the action directly. In most games, the actions available are state-dependent anyway, so you cannot easily formulate them as ANN outputs.
So the idea is that at each state, you consider the alternative actions, and the one that leads to the most valuable state is the action of choice (without using lookahead). Your ANN will thus be approximating the board state values
Strictly speaking for tic-tac-toe you don't need a neural network, the tabular Q-learning method would suffice. Have you read Sutton and Barto book on RL?


text:
Wouldn't convolutional neural network models work better without flattening the input in any stages?

The above model is what really helped me understand the implementation of convolutional neural networks, so based on that, I've got a tricky hypothesis that I want to find more about, since actually testing it would involve developing an entirely new training model if the concept hasn't already been tried elsewhere.
I've been building a machine learning project for image recognition and thought about how at certain stages we flatten the input after convoluting and max pooling, but it occurred to me that by flattening the data, we're fundamentally losing positional information. If you think about how real neurons process information based on clusters, it seems obvious that proximity of the biological neurons is of great significance rather than thinking of them as flat layers, by designing a neural network training model that takes neuron proximity into account in deciding the structure by which to form connections between neurons, so that positional information can be utilized and kept relevant, it seems that it would improve network effectiveness.
Edit, for clarification, I made an image representing the concept I'm asking about:

Basically: Pixels 1 and 4 are related to each other and that's very important information. Yes we can train our neural network to know those relationships, but that's 12 unique relationships in just a 3x3 pixel grid that our training process needs to successfully teach the network to value, whereas a model that takes proximity of neurons into consideration, like the real world brain would maintain the importance of those relationships since neurons connect more readily to others in proximity.
My question is: Does anyone know of white papers / experiments closely related to the concept I'm hypothesizing? Why would or would that not be a fundamentally better model?

I have had similar thoughts about neural networks before. Convolution layers are layers of two dimensional nodes effectively passing the spacial data so why don't we use two dimensional hidden layers to receive information out of them.
I'm sure someone has used this type of implementation before. I believe the papers bellow are using this. Part of the point of neural networks is that the weights are trained in order to optimize finding the best solution so regardless of the spacial information it learns to 'focus'/increase weight on locations that are associated with deciding the solution.
Think of the problem where your neural network examines an image and gives true or false. Training images are True if the center is red and one of the corners is blue or if the center is blue and one of the corners are red. Flattening the layers or not should have basically no effect on this model. In other circumstances like object detection or labeling outlines yes I believe not flattening will benefit the model. With that said flattening the data does not erase spacial relationship each layer will still be trained to detect the spacial information that gives a correct answer the flattened layers just won't have the benefit of neighbors when the layers are one dimensional instead of two.
In a a CNN with multi class detecting as the task you could allow each class to have its own CNN like hidden layers that narrow to a decision node and decide if they match that class or not. Imagine a palm tree shape where the palm trunk is the image convolutions and each leaf on the top are the two dimensional hidden layers that narrow to an output layer.
 Multi-dimensional NN    and
 Three dimensional Neural Network
I know I spoke in a lot of abstraction so if any part doesn't make sense, I'll make an edit to clarify.

Read on Fully Convolutional Networks (FCN). There is a lot of papers on the subject, first was "Fully Convolutional Networks for Semantic Segmentation" by Long.
The idea is quite close to what you describe - preserve spatial locality in the  layers. In FCN there is no fully connected layer. Instead there is average pooling on top of last low-resolution/high-channels layer. The effect is like as if you have several fully connected layer centered on different locations and end result produced by weighted voting of them.
Pleasant side effect of FCN is that they work on any spatial image size(bigger then receptive field) - image size is not coded into network.

Do you know are papers where they compare them to CNN+FC networks? I was experimenting with them fa while ago and found FCN perform worse compared to CNN+FC layers. Only when I build first layer of convolutions like in the inception by using filters of different size on the input - I got something comparable, at the expense of computation time. It would be interesting to know more about the architecture they use.

Generaly FCN works same or better then CNN with fully connected, but the number of channels in the last layer should be comparable to size of fully connected layer. Im dont not recall specific papers though.

FCN are not necessarily better than CNN+FC, however they are more flexible. For instance you can train a FCN on 512x512 images and do inference on 416x416 images. You can also use transfert learning without depending on the image size.