How do I poison an SVM with manifold regularization? I'm working on Adversarial Machine Learning, and have read multiple papers on this topic, some of them are mentioned as follows:

Poisoning Attacks on SVMs: https://arxiv.org/pdf/1206.6389.pdf
Adversarial Label Flips on Support Vector Machines

However, I am not able to find any literature on data poisoning for SVMs using Manifold regularization. Is there anyone who has knowledge about that?

I think, one could generate a data set, with a random variable in each component of the data vector, add this data to the training data set, and then shuffle the combined data set.


When does AlphaZero play suboptimal moves? If AlphaZero was always playing the best moves it would just generate the same training game over and over again. So where does the randomness come from? When does it decide not to play the most optimal move?

During the self-play training process, AlphaZero does not greedily play only the moves it thinks are "best" (which would normally be the move with the highest visit count leading out of the root node of the MCTS search tree). Instead, for the purpose of generating a more diverse set of experience, it samples moves proportionally to the visit counts. This means that in any given situation encountered during self-play, the move considered to be "optimal" will still have the largest probability of getting picked, but other moves will also have smaller probabilities of getting picked. In theory, it might even sometimes pick the move that it expects to be the worst one (very rarely)!

If I recall correctly, they only did what I describe above for the first 30 moves of any game, and afterwards move on to greedy play. This still results in a very diverse set of 30-move-starts for every game it experiences though. I'm not 100% sure if I remember this detail correctly though, maybe they only did this earlier (in AlphaGo Zero for example), and no longer do it in AlphaZero. Would have to check the paper to make sure.

Additionally, whenever they start a new search process, they perturb the prior probabilities assigned by the learned policy network to all the moves available in the root node. This is done in a non-deterministic way using Dirichlet noise. I think this is not really explicitly mentioned in the AlphaZero paper, but it is in the Supplementary Materials (and also in the AlphaGo Zero paper?). Anyway, this also means that if precisely the same game state is encountered twice in two different games of self-play, the search behaviour may be slightly different due to the introduced stochasticity, and hence it may come to a different conclusion as to what move is "optimal".


AI that maximizes the storage of rectangular parallelepipeds in a bigger parallelepiped As you can see in the title, I'm trying to program an AI in Java that would help someone optimize his storage.

The user has to enter the size of his storage space (a box, a room, a warehouse, etc...) and then enter the size of the items he has to store in this space. (note that everything must be a rectangular parallelepiped) And the AI should find the best position for each item such that space is optimized.

Here is a list of what I started to do :

I asked the user to enter the size of the storage space (units are trivial here except for the computing cost of the AI, later on, I'm guessing), telling him that the values will be rounded down to the unit
I started by creating a 3-dimensional array of integers representing the storage space's volume, using the 3 values taken earlier. Filling it with 0s, where 0s would later represent free space and 1s occupied space.
Then, store in another multidimensional array the sizes of the items he has to store And that's where the AI part should be starting. The first thing the AI should do is check whether the addition of all the items' volumes doesn't surpass the storage space's volume. But then there are so many things to do and so many possibilities that I get lost in my thoughts and don't know where to start...

In conclusion, can anyone give me the proper terms of this problem in AI literature, as well as a link to an existing work of this kind? Thanks

A simple approach that gives a good baseline for such problems is simulated annealing. The idea is that you do something random. If it improves things, then it is good. If it makes things worse, you still take it with some probability $p$, where $p$ shrinks over time.

The more bad solutions you can rule out beforehand / the smarter you can encode your problem, the better solutions simulated annealing will give.


What is the difference between continuous domains and discrete combinatorial optimization? According to this website: http://yarpiz.com/67/ypea104-acor (in the website it is mentioned that it is a project aiming to be a resource of academic and professional scientific source codes and tutorials.):

  "Originally, the Ant Algorithms are used to solve discrete and
  combinatorial optimization problems. Various extensions of Ant Colony
  Optimization (ACO) are proposed to deal with optimization problems,
  defined in continuous domains. One of the most useful algorithms of
  this type, is ACOR, the Ant Colony Optimization for Continuous
  Domains, proposed by Socha and Dorigo, in 2008 (here)."

What is the difference between continuous domains and discrete combinatorial optimization? I appreciate if you could also mention some examples for each type.

A continous domain can be imagined as a space in which the axes of the coordinate systems are the parameters of the continous domain. If we take 2D Cartesian space as an example, it is a continous domain where there is an infininite amount of possibilities of placing an object in this space. Let's call the position of the object its state. Constraining the space to e.g. a sheet of paper does not change its continuity. There is still an infinte amount of posibilites of placing a dot (or any object) on that sheet of paper or with other words the state space of the dot is still infietly large.

Computational methods are much better in dealing with descretet spaces (mainly because the possiblities to take the next step is limited). In a discrete space the possibilities are limited. If we take the example above and discretize the sheet of paper, e.g. use a grid on the paper and say that we are not interested in the exact location of the point, just in which grid it is in we have succesfully defined a discrete space.

A different example for a problem in descrete domain can be navigation on a map. If we assume that the exact rajectory is not important, then we can make descrete decisions of turning left, right or moving forwards or backwards by one step. Even if add further possibilites (like moving up one step or down) until the number of possibilities in one state is not infinite the domain is descret.


A good way to understand the mathematical details of variational autoencoders through implementation? As a researcher, I am getting interested in deep learning (as everyone else:)), and I decided to start with the variational eutoencoders, since I am more interested in unsupervised than supervised learning. I have already read tutorials on the general idea of the mechanism of VAE, and what people usually suggest is to use TensorFlow, Keros, etc. to implement them. However, I do not just want to use machine learning, but also want to develop novel algorithms on top of the existing ones, so I want to deeply understand the mathematical details. And in my experience, in order to understand them, reading is not enough, you need to implement. Any suggestions on where/how to start? I have a general machine learning and programming background, but no experience on deep learning. I even don't know what exactly back-propagation is used for, if this would help.

I even don't know what exactly back-propagation is used for, if this would help.

Programming backprop manually is one of the best exercises in machine learning. In fact, to do this you don't need a special package, like Tensorflor or Keras, just a general computing library like NumPy (and a whiteboard).

Though I dare to say that VAE is not the best thing to implement, if you are not 100% familiar with backprop. It's pretty advanced technique and you risk to mix up fundamental (e.g. backprop) and specific ideas (e.g. deliberately crafted loss function) and slow down your understanding.

I really think that writing a simple feed-forward neural net (including forward and backward passes) is a very good starting point, after which you can move on to VAE details, if you'd like.

  Any suggestions on where/how to start?

If you feel confident with algebra and calculus, I highly recommend this Stanford course, especially its assignments. The course itself is about computer vision and convolutional neural networks, but the first assignments are very general and will give a lot of insight of what and how neural networks are doing.


What are the benefits of the VGDL over the ALE? For benefits of testing AGI, is using a high-level video game description language (VGDL) gives more reliable and accurate results of general intelligence than using Arcade Learning Environment (ALE)?

Here is a description of the input to an ALE agent:
Percept state: A single game screen (frame): a 2D array of 7-bit pixels, 160 pixels wide by 210 pixels high.
Actions: 18 discrete actions defined by the joystick controller

Regarding VGDL, as far as I can see, the main site associated with it is gvgai.net, which is currently down. The associated API is described in this paper.

Percept state for GVGAI is more structured than for ALE, but the closest correspondence to ALE appears to be an 'Observation grid', consisting of a 2D array of sprite identifiers.

Actions: ACTION_NIL, ACTION_UP, ACTION_LEFT, ACTION_DOWN, ACTION_RIGHT and ACTION_USE (stated as 'typical' values).

Of the two, it would seem that ALE is more suitable for AGI, because of the more 'free form' nature of the input.

However, one of the issues with either of these approaches is that the set of possible actions is strongly constrained. These domains are therefore 'operationalised' - the hard task of working out what actions are possible has already been solved for the AI by the API, effectively acting as a bottleneck on the complexity of mapping from input to output.

A range of alternative game-playing frameworks are listed here and one alternative (which I personally believe is more useful for AGI purposes) is the Artificial Text Adventurer, in which (at each turn) agent is presented with natural language input describing the scene and must then output a command in natural language. Disclaimer: I am associated with this competition.


Solving the supervised learning problem of learning $p(y \vert \mathbf{x})$ by using traditional unsupervised technologies to learn $p(\mathbf{x}, y)$ I am currently studying Deep Learning by Goodfellow, Bengio, and Courville. In chapter 5.1.2 The Performance Measure, $P$, the authors say the following:

Unsupervised learning and supervised learning are not formally defined terms. The lines between them are often blurred. Many machine learning technologies can  be used to perform both tasks. For example, the chain rule of probability states that for a vector $\mathbf{x} \in \mathbb{R}^n$, the joint distribution can be decomposed as
$$p(\mathbf{x}) = \prod_{i = 1}^n p(x_i \vert x_1, \dots, x_{i - 1} ).$$
This decomposition means that we can solve the ostensibly unsupervised problem of modeling $p(\mathbf{x})$ by splitting it into $n$ supervised learning problems. Alternatively, we  can solve the supervised learning problem of learning $p(y \vert \mathbf{x})$ by using traditional unsupervised technologies to learn the joint distribution $p(\mathbf{x}, y)$, then inferring
$$p(y \vert \mathbf{x} ) = \dfrac{p(\mathbf{x}, y)}{\sum_{y'}p(\mathbf{x}, y')}.$$

I found this part vague:

Alternatively, we can solve the supervised learning problem of learning $p(y \vert \mathbf{x})$ by using traditional unsupervised technologies to learn the joint distribution $p(\mathbf{x}, y)$, then inferring
$$p(y \vert \mathbf{x} ) = \dfrac{p(\mathbf{x}, y)}{\sum_{y'}p(\mathbf{x}, y')}.$$

Can someone please elaborate on this, and also explain more clearly the role of $p(y \vert \mathbf{x} ) = \dfrac{p(\mathbf{x}, y)}{\sum_{y'}p(\mathbf{x}, y')}$?
I would greatly appreciate it if people would please take the time to clarify this.

This is the definition of conditional probability + Total probability decomposition formula:

$p(y|x) = \frac{p(y,x}{p(x)} = \frac{p(x,y)}{\sum_{y'}p(x,y')}$.

The idea is to use some unsupervised learning algorithm to learn the distribution $p(x,y)$ for every possible value of $y$, and by using the previous formula you can find $p(y|x)$.


Is it possible that every class has a higher recall than precision for multi-class classification? I am a student learning machine learning recently, and one thing is keep confusing me, I tried multiple sources and failed to find the related answer.
As following table shows (this is from some paper):

Is it possible that every class has a higher recall than precision for multi-class classification?
Recall can be higher than precision over some class or overall performance which is common, but is it possible to keep recall greater than precision for every class?
The total amount of test data is fixed, so, to my understanding, if the recall is greater than the precision for one class, it is a must that the recall must be smaller than the precision for some other classes.
I tried to make a fake confusion matrix to simulate the result, but I failed. Can someone explain it to me?
this is a further description:
Assume we have classified 10 data into 3 classes, and we have a confusion matrix like this,

if we want to keep recall bigger than precision over each class (this case 0,1,2) respectively, we need to keep:
x1+x2 < x3+x5
x3+x4 < x1+x6
x5+x6 < x2+x4
There is a conflict, because the sum of the left side equals to the sum of the right side in these inequalities, and the sum(x1...x6) = 10 - sum(a,b,c) in this case.
Hence, I think to get recall higher than precision on all classes is not feasible, because the quantity of the total classification is fixed.
I don't know am I right or wrong, please tell me if I made a mistake.

In the case of binary classification, i.e. when you have two classes $A$ and $B$, the recall is defined as
$${\displaystyle {\text{Recall}}={\frac {tp}{tp+fn}}}$$
Similarly, the precision as
$${\displaystyle {\text{Precision}}={\frac {tp}{tp+fp}}}$$
where, if you choose and fix a class $A$ as your main class (or class of interest),

$tp$ is the number of true positives (i.e. the number of observations that have been classified as $A$ and actually belong to class $A$, i.e. they have been correctly classified)

$fn$ is the number of false negatives (i.e. the number of observations that have been incorrectly classified as $B$, so, in this case of binary classification, they actually belong to class $A$)

$fp$ is the number of false positives (i.e. the number of observations that have been incorrectly classified as $A$)

In this context, the confusion matrix will be a $2 \times 2$ matrix because you have two predictions (one for each of the two classes) compared against the two ground-truth labels (or classes).
In the context of multi-class classification, where you have $N > 2$ classes, you will have a $N \times N$ confusion matrix, for the same reason. In this case, the recall and precision are just an extension of the binary classification problem. More precisely, let $M$ represent your confusion matrix, so $M_{ij}$ is the entry of this confusion matrix at row $i$ and column $j$. Then the recall, for class $i$ (i.e. your main class, as $A$ above), is defined as
$$\text{Recall}_{~i} = \cfrac{M_{ii}}{\sum_j M_{ij}}$$
$$\text{Precision}_{~i} = \cfrac{M_{ii}}{\sum_j M_{ji}}$$
In other words, the recall for a certain class $i$ is computed as the fraction of the diagonal element $M_{ii}$ and the sum of all elements in that row $i$. Similarly, the precision is computed as the fraction of $M_{ii}$ and the sum of all elements in column $i$.
If the true positives (i.e. the diagonal elements $M_{ii}$) of all classes are indeed bigger compared to the denominator, the recall can indeed be bigger than the precision for all classes.


Is there a taxonomy of adversarial attacks? I am a medical doctor working on methodological aspects of health-oriented ML. Reproducibility, replicability, generalisability are critical in this area. Among many questions, some are raised by adversarial attacks (AA).
My question is to be considered from a literature review point of view: suppose I want to check an algorithm from an AA point of view:

is there a systematic methodology approach to be used, relating format of the data, type of models, and AA? Conceptually, is there a taxonomy of AA? If so, practically, are some AA considered as gold standards?

There are already a couple of papers in the literature that attempt to provide a taxonomy and survey of adversarial attacks. I will just list the two that I think are reliable enough that you can probably use as a reference.

A taxonomy and survey of attacks against machine learning (2019) by Nikolaos Pitropakis et al., published in Computer Science Review

Adversarial Examples: Attacks and Defenses for Deep Learning (2019) by Xiaoyong Yuan et al., published in IEEE Transactions on Neural Networks and Learning Systems.

Needless to say, there are different adversarial attacks, such as the Fast Gradient Signed Method (FGSM), and they can be classified into different categories, such as evasion attacks or poising attacks. You can find a lot more info in these cited papers.


What is the mathematical definition of an activation function? What is the mathematical definition of an activation function to be used in a neural network?

So far I did not find a precise one, summarizing which criterions (e.g. monotonicity, differentiability, etc.) are required.  Any recommendations for literature about this or – even better – the definition itself?

In particular, one major point which is unclear for me is differentiability. In lots of articles, this is required for the activation function, but then, out of nowhere, ReLU (which is not differentiable) is used. I totally understand why we need to be able to take derivatives of it and I also understand why we can use ReLU in practice anyway, but how does one formalize this?

There is no strict definition of suitability of an activation function for neural networks. Instead there are a number of desirable traits, and functions that don't meet them or come close enough may perform badly in general (but those functions may still work in specific cases)

If you are using gradient descent as a training method, then differentiability is closest to being a requirement. However, even then as you noticed with ReLU, it is not an absolute requirement, provided behaviour close to discontinuities is good. For example $\frac{1}{x}$ or $log{x}$ make bad choices here due to how they behave for values near to $0$.

Wikipedia summarises some important desirable traits, plus compares popular activation functions in this table.

  Nonlinear – When the activation function is non-linear, then a two-layer neural network can be proven to be a universal function approximator. The identity activation function does not satisfy this property. When multiple layers use the identity activation function, the entire network is equivalent to a single-layer model.

  Range – When the range of the activation function is finite, gradient-based training methods tend to be more stable, because pattern presentations significantly affect only limited weights. When the range is infinite, training is generally more efficient because pattern presentations significantly affect most of the weights. In the latter case, smaller learning rates are typically necessary.

  Continuously differentiable – This property is desirable (RELU is not continuously differentiable and has some issues with gradient-based optimization, but it is still possible) for enabling gradient-based optimization methods. The binary step activation function is not differentiable at 0, and it differentiates to 0 for all other values, so gradient-based methods can make no progress with it.

  Monotonic – When the activation function is monotonic, the error surface associated with a single-layer model is guaranteed to be convex.

  Smooth functions with a monotonic derivative – These have been shown to generalize better in some cases.

  Approximates identity near the origin – When activation functions have this property, the neural network will learn efficiently when its weights are initialized with small random values. When the activation function does not approximate identity near the origin, special care must be used when initializing the weights.

You can see that ReLU is an outlier on more than one of these traits. The reason that it is popular is that despite these weaknesses, the things it does well - speed of operation plus helping combat the vanishing gradient problem - make it a solid choice for very deep networks. In fact the success of ReLU has inspired use of a number of similar-looking activation functions that hope to keep its benefits whilst having more of these desirable traits.

Ultmately though, almost any non-linear function can be used successfully in a neural network. The more of the desirable traits it has, the more likely you can use it in general cases with existing approaches to training.


Decision tree: more than 2 classes, how to represent elements that are in a class vs ones that aren't? I'm building a decision tree and would like to separate (for example) the elements that are in class 0 from those in classes 1 and 2, case in point:

df = pd.DataFrame(np.random.randn(500,2),columns=list('AB'))
cdf = pd.DataFrame(columns=['C'])
cdf = pd.concat([cdf,pd.DataFrame(np.random.randint(0,3, size=500), columns=['C'])])
#df=pd.concat([df,cdf], axis=1)
(X_train, X_test, y_train, y_test) = train_test_split(df,cdf,test_size=0.30)
y_train=y_train.astype('int')
classifier = DecisionTreeClassifier(criterion='entropy',max_depth = 2)
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)

C represents the class of an element,A and B are two variables that define the element, how can I build a tree that instead of dividing results into C=0, C=1 or C=2 divides them into C=0 and C!=0?

I don't think that is possible with a decision tree, unless there is some measure of confidence that you can use as a threshold.

I ran into the same problem with the ID3 algorithm. It assigns classes, but you only have the resulting class without any confidence or probability attached.

One possible solution could be to add a number of counter examples as a second (dummy, catch-all) class; if the elements of C = 0 are reasonably tightly clustered and your counter examples for C != 0 cover the remaining problem space, then that might work.


How to label edited images after data augmentation? I am new to neural networks, I've only started studying and learning about the subject a year ago, and I just started building my first neural network.
The project is a little bit ambitious: A browser extension for children's safety,  it checks for sexual or abusive content, so that it replaces that content with a placeholder, the user will have to insert a password to show original content.
I didn't find a dataset online, so I decided to build my training dataset. So, I started by writing a web crawler, it starts collecting images, meanwhile implementing data augmentation techniques. It basically resizes images (to 95x95), crops them, rotates, changes colors, adds blur, black and white, noise, etc.
The problem is that after applying these techniques, I noticed that some images are not even recognizable by a human subject.
I mean that even though I know that picture contains sexual content, it doesn't even appear to be sexual anymore.
So, do I have to label it as sexual or not sexual?
Notice that it's easier for me to consider it as sexual, if every image produces about 50 edited images, I'd only have to label the original image, what follows is that all 50 images get the same label. Is it okay to do just that?

This is a sample of what I get after doing data augmentation, notice that some pictures are not recognizable by humans.
For example, look at the result after editing images hue and saturation, a human can't recognize this result, is it okay to label it: not sexual?

I wouldn't recognize the picture on the right if I didn't see the original one.
I also tested this on human subjects (my brothers), they didn't recognize the squirrel on the right.

Yes, you should label it the same. But more importantly you need to make sure that each perturbation of the image doesn't change some important character of the image.

Consider training an apple classifier. If you plan to augment data by altering the RGB values, you need to be wary that you might cause issues in classification tasks where color is instrumental. Say, Granny apple / Fuji apple. If you still really want to augment data in this way, consider perturbing by smaller amounts each time.

Or consider an apple detector. An apple still "looks to be an apple" if looked at an angle, if looked through a mirror, if looked afar, but probably not if looked through a carnival mirror.

So ask yourself, if an image still NSFW if the colors are changed?

However, as a personal anecdote I don't think augmenting data by changing the color channel is a good idea. Also note that training on augmented data by altering the color channels as a whole should be more or less equivalent to training in B/W. Why?


Can I recognize the faces of people around the world? I created a system where every moment takes photos of the face of who is in the vision of the camera. Initially I took 500 photos of me, to recognize its creator. This takes approximately 20 seconds.

Then every moment he recognizes faces and if it is me, he knows that his creator is present. Any different face, it creates a dataset with a different name and starts taking up to 500 photos to also recognize these faces.

When I say a certain command, it returns all faces I have found that have no ID.

I'm looking for ways to capture the images through some camera that I can carry while walking on the street and in public places.

The problem is that there would be several faces to name. I'm partially solving this problem by trying to recognize these people in social networks. I check the region where the photo was taken and try to find people who have checked in or liked the area on Facebook. But anyway, this is not the big problem, although it is looking for more effective solutions.

  My big problem is: Can I do this? Do I have this right? Can I record a
  robber robbery and recognize his face in other places? Record an
  aggression, an act of prejudice and things like that?

The main purpose would be this, but could also be used for other purposes. My fear is being arrested for doing this. Both because he would be taking pictures of people without his consent.

ps: I'm thinking of having a camera in the palm of my hand. It would be a micro camera (I'm trying to find the product on the Internet), to be as discreet as possible.

I thought it might be a helpful place to start:
https://en.wikipedia.org/wiki/Google_Street_View_privacy_concerns
The wiki is well cited, so should lead to some useful tidbits.  They break it down by continent and country.
Seems like a parallel to what you're doing, although, if you're not making your data public, I doubt you'll be facing the same privacy issues.
Also relevant would be: https://en.wikipedia.org/wiki/Expectation_of_privacy

Examples of places where a person has a reasonable expectation of privacy are a person's residence or hotel room and public places which have been specifically provided by businesses or the public sector in order to ensure privacy, such as public restrooms...
In general, one cannot have a reasonable expectation of privacy in things held out to the public.

My understanding is that there is no expectation of privacy in public places where you'd be capturing the images.


predict waste generation I am starting a project to predict the generation of urban waste.

I have found very little information on this topic on the internet.
I would be very useful advice on how to approach this topic, and what techniques you would use.

I have found academic articles that make predictions with feedforward neural networks. But they seem basic or old.
I would expect the use of recurrent networks, but all the examples I find on the internet are about climate prediction, or economics. And they are very different topics.

It would be very useful to make the prediction of waste generation based on an existing model, and not something invented by me. On what topic would you recommend that I take as a base?

I appreciate any advice.
regards

It is correct that climate and economic models are distinct from waste models.

A memory based model is the correct approach because the time domain is key in prediction based on existing trend data.  However, the RNN is not a practical production model with others that have proven more productive.  Although this article is trendy and not accurate in every technical respect, it introduces the more effective models and their relationship to RNNs.  If you study the article and the terms it introduces on the web, the right solution and possibly an open source project that can get you started can be found.

Basis for Prediction of Urban Waste

Whether modelling solid or liquid waste, the following model is recommended by two consultants to several large European municipal clients.  All the variables and distributions are time dependent.

$v(t) = n(t) \; d\big(I(t), A(t), t\big) \; s(t) \; r(\vec{x(t)}, t)$

$v$ is the waste rate in metric tons per week
$n$ is the population of the collection region
$d$ is the average demographically based disposal rate in Kg per person – Income and age affect consumption and the waste products of consumption, affecting disposal.
$I$ is the distribution of income
$A$ is the distribution of age
$s$ is the dimensionless seasonal factor
$f$ is the dimensionless regional factor – The granularity of regions depends on variance considerations.
$\vec{x}$ is a vector of non-demographic factors that are likely to correlate with regional waste rates, such as number of university students, size of recycling receptacles, or number of fast food restaurants

Although some of the above factors can be combined in a single training process, there are advantages of leaving them as separate factors.

Demographics is measured at the municipal level and has its own model that can be trained based on immigration, emigration, births, deaths, and aging.  Proven models exist for this already.
Separation of training models allows for component wise system development and the understanding of relationships in data that would remain opaque if training was aggregated.

Each of the distributions can be obtained from municipal data. Labeled data for $n, d, s,$ and $r$ can be measured by implementing the appropriate municipal data collection processes.  If it is already available, that would be unusual, and cleaning the data (data sanitation) would be an important consideration.

Once labeled data is available for training and the artificial network design is selected, training can occur, followed by testing, followed by validation.  As the system is deployed, care would need to be taken to continuously refine the artificial network hyper-parameters for monthly, quarterly, or annual training and continue to improve data collection accuracy and reliability.

High accuracy and reliability in such prediction could be expected for short term.  Longer term prediction may have considerably lower accuracy and reliability because of the higher probably of the occurrence of new types of social and economic shift around which the model could not have been advanced trained.


Do AIs based on MCTS start each game from scratch? AIs that rely on MCTS - like AlphaGo - create their decision tree as the game progresses. Do they start from scratch each game and build a new tree or do they keep the tree and grow it from game to game further?

Besides the possible limitations of storage space for the search tree, I don't see any obvious drawback in keeping and growing the tree, which seems to me to be the preferred option. Are there other reasons to start from scratch each game?

Your intuition is right. The tree is grown after each game.

Before the first play through, the values of each decision point are initialized (randomly or to some constant). Then at the end of one play through, the weights of the decision points are updated using Monte Carlo methods. In this way, on the next play through, the updated weights help the agent make a decision in the next game.

As for how the decision points are added to the tree, it depends on the application. For simple games like TicTacToe, we know all of the decision points. For big games, there are methods to trim the tree of bad performing branches.


When calculating the cost in deep Q-learning, do we use both the input and target states? I just finished Andrew Ngs's deep learning specialization, but RL was not covered, so I don't know the basics of RL. So, I have been having trouble understanding the cost function in deep Q-learning. Like other cost functions in machine learning, you usually have $\hat{y}$ (the network prediction) and $y$ (the target, or what the network is being optimized for.)
I've read through a few online articles on deep Q-learning. So far, there has been no mention of setting up a target state ($y$) for the agent to produce. There has been mention of calculating a temporal-difference, however, which is where I am confused.
When calculating the cost function, are you taking the input state ($\hat{y}$) and a target state ($y$) into consideration to determine the temporal-difference?
Otherwise, I'm not sure how the cost function could determine a reward based on the input alone (state of the environment the agent is in.).

I will first explain briefly to you the difference between supervised learning and reinforcement learning to make sure that you don't have any misunderstandings. In supervised learning you are provided with some data $\{(\textbf{x}_i, y_i)\}_{i=1}^n$ where $\textbf{x}_i$ are the features for data point $i$ and $y_i$ is its true label. Now, the aim of supervised learning is to learn a function $f$ that can accurately predict the label of a data point given its features. In deep learning this function is a neural network, $f_\theta(\cdot)$. To optimise the parameters we obtain the models prediction for the label of $y$, denoted typically by $\hat{y} = f_\theta(x)$ and we look to optimise the parameters of the function $\theta$ by minimising the loss $\mathcal{L}(\hat{y}, y)$ (note that here the loss is a function $\mathcal{L}: \mathcal{Y} \times \mathcal{Y} \rightarrow \mathbb{R}$.
In reinforcement learning things are quite different. We are not provided with any data. Instead we have a Markov Decision Process (MDP) and an environment that we can interact with. The state space is defined by the MDP and we can get samples, mainly tuples of the form $(s, a, r, s')$, that we can use to teach our agent how to find an optimal policy - typically an optimal policy is one that takes an action given the current state that will maximise the sum of the future rewards of the episode. So in reinforcement you can probably see that things are quite different to supervised learning, mainly in the way that we 'obtain' our data.
Of course these explanations are gross oversimplifications of the learning process in both paradigms and should only be used as a brief example to try to emphasise the different between the two learning paradigms.
Now, there are two ways you can parameterise your Q-function using a neural network:

The network takes as input the current state and outputs Q-values for each potential action; i.e. the output is a vector in $\mathbb{R}^{|\mathcal{A}|}$;
The network takes as input the state and action and outputs a real number which is the Q-value for the state, action tuple you pass as input to the network.

The second way is usually reserved for instances where you have a huge action space but only ever would consider a few feasible actions at each state - this saves computational complexity.
Now, to answer your question:
In case 1) you are assumed to have access to a transition tuple $(s, a, r, s')$. The temporal difference, which we will use as the target, is $\hat{y} = r + \max_a Q(s', a)$. Now, as our output of $Q(s', \cdot)$ is an $\mathbb{R}^{|\mathcal{A}|}$ what we do is make a forward pass of the network for the current $(s, a)$ tuple, i.e. we get $x = Q(s, a)$, and then change the element that corresponds to the action which satisfies $\arg\max_a Q(s', a)$ of $x$ to $\hat{y}$, so we have now got our augmented input $\tilde{x}$ which serves as our target.
To make that step a bit clearer, suppose we have a 2-dimensional action space and the $\arg\max_a Q(s', a)$ is the action in the first dimension, then we would change the first dimension of $x$ to be $\hat{y}$.
We then train the network using the Mean Squared Error Loss between $x$ and $\tilde{x}$ - note that no gradient information is retained when we do the forward pass to get $\tilde{x}$; in fact we usually don't use a current version of the $Q$ network, we use an 'old' version of the network called the target network (I imagine there's probably a question about this network on the site already so I won't explain it in detail).
In case 2) the idea is much more simple as the outputs of the network are scalars so you can just train your network using the MSE between the scalar values of $Q(s, a)$ and $\hat{y}$ as defined above, the caveat here is that to calculate $\arg\max_a Q(s', a)$ you have to make $|\mathcal{A}|$ forward passes of the network for all possible $(s', a)$, for fixed $s'$, tuples which is why method 1) is usually preferred.
Now, whilst we may use techniques from supervised learning to optimise the Q-function, you can hopefully see the differences between supervised and reinforcement learning.
In short, the temporal difference is the target that you train your network towards being able to predict, and the state is (typically) the input into your neural network. For a more in depth discussion of RL being framed as supervised learning please see this answer.


What is correct update when the some indexes are not available? To update the Q table Q-learning takes the arg max of the Q values - the state, value mappings.

For example, in tic tac toe the state XOX OXO -X- contains two available positions, each marked by the - character. In order to evaluate the arg max should temporal difference calculate the arg max of just the available positions?

For the state XOX OXO -X- the arg max should be taken at index 6 and 8 ? (assuming zero indexing) If not then how should the arg max indexes be updated? The indexes 0,1,2 3,4,5 7 can be used as they are already been taken by X or O so should not be evaluated for their value ? This also means that indexes which are not available will not have their Q value updated, will this break the Q-learning procedure ?

What you are referring to as the situation where

  some indexes are not available

is simply the situation where some actions are not available/valid in some state. So, yes, the ${\arg \max }$ will be calculated based only on the available actions in that state. More formally,
$$\underset{a \in \mathcal{A}(s)}{\arg \max } \, Q(s, a)$$

where $Q(s,a)$ has been initialized for all $s \in \mathcal{S}^{+}$ and $a \in \mathcal{A}(s)$ and $\mathcal{A}(s)$ is defined as the set of all actions available in state $s$.
See Sutton and Barto's Intro to RL book, chapter 6 (the part on Q-learning).

In the same book (chapter 3), the authors state that:

  To simplify notation, we sometimes assume the special case in which
  the action set is the same in all states and write it simply as $\mathcal{A}$.

Therefore, in many sources, you may see the $\arg \max$ expressed as $\underset{a \in \mathcal{A}} {\arg \max}$ or even $\underset{a} {\arg \max}$. It's implicit that it is taken with respect to the set of actions $\mathcal{A}(s)$ available in state $s$.


What is the order of the genetic operations in NEAT? I was trying to implement NEAT, but I got stuck at the speciating of my clients/genomes.

What I got so far is:

the distance function implemented,
each genome can mutate nodes/connections,
two genomes can give birth to a new genome.

I've read a few papers, but none explicitly explains in what order what step is done. What is the order of the genetic operations in NEAT?

I know that for each generation, all the similar genomes will be put together into one species.

I have other questions related to NEAT.

Which neural networks are killed (or not) at each generation?

Who is being mutated and at what point?

I know that these are a lot of questions, but I would be very happy if someone could help me :)

What is the order of the genetic operations in NEAT?

You start by evaluating all of the initial neural networks and compute their initial fitness.
Then you speciate,
kill off the worst neural networks,
mutate and crossover to produce offspring, and
evaluate again.

The order of events is described on page 109 onwards in the original NEAT paper.

  Which neural networks are killed (or not) at each generation?

The neural networks with the worst performance are killed off after speciation. None of the neural networks survive - the entire population is replaced with the offspring of the nets remaining after the culling stage. That said, you can implement elitism, where you keep some small portion of the best-performing nets and carry them over to the next generation without mutating them, but that is optional.

  Who is being mutated and at what point?

At the end of each generation, after speciation and culling. To produce offspring, some of the remaining nets are subjected to mutation (think asexual reproduction - like single-celled organisms - but the offspring is mutated so that it differs from the parent). The rest are subjected to crossover in random pairs, so this would be the equivalent of sexual reproduction where you need two parents.

Hope that helps.


How to add more than 1 agent in one generation with Q Learning Sometimes the agent learns a bit slow and you want to have multiple agents in one generation. And at each episode you'll draw on the screen only the best of them or all of them. How is that possible?

For clarification purposes, please watch this video on youtube at time 4:10.

I need just a theoretical approach, I'll try the coding myself :).

Thanks for any answer! I really do appreciate it! :)

The video you linked is not using reinforcement learning (RL). It is using genetic algorithms (GA).

GA is designed around using multiple agents and picking the best performing to move forward to next generation. With this approach, it is common to want to only view the best performing agents, as the learning mechanism uses the same selection process - the best agent is the output of the algorithm*.

Whilst you can run muliple agents to collect more data easily enough in RL, they typically won't perform better or worse other than by random chance. The best performance is not indicative of the agent's overall performance in the way that GA is, because there is only one agent. It would not be as meaningful to pick out the best ones for display. Instead, after a certain number of training episodes, you should take the agent so far, stop it running exploratory moves (set $\epsilon = 0$ if you are using $\epsilon$-greedy exploration). Then render the behaviour of that agent.

If you want to compare RL versus GA for learning efficiency, then one arguably fair comparison would be to render the agent each time it has trained on a number of episodes in RL equal to the population size used in the GA version. If you are only showing results after every 100 generations of GA, then multiply number of training episodes by 100 to compare using the same amount of data input.

You can also, separately to this concern, run RL with multiple exploring agents at once. If you want to have parallel training with multiple environments running in RL, then you will need a distributed environment. Each instance of the environment would run one agent, and collect training data. You have a rough choice between:

Feeding everything observed into one central experience replay memory and a single training loop routine samples from the whole memory and updates the agent. This should work OK for Q-learning.
Calculate update gradients on each distributed environment, collate them centrally and update the agent on a mean gradient update step before sending out the updated agent to all the distributed systems. This is the approach typically used by A3C and A2C which benefit from having multiple agents running at once.

In both cases, the latest parameters of the agent (the neural network weights) need to be regularly copied out to each environment so that each instance can work as much as possible with a current policy.

Setting up a distributed learning environment for RL is more work than for GA, because you need to move a lot more data between agents to complete learning, whilst for GA you only need to measure fitness. However, you should find that Q learning can be a lot more efficient (in terms of number of simulations required) than a GA-based approach for many control problems.

* As an aside, this can be a weakness of GA if you are running in an environment with random choices or events - the GA can select as it's "best" result at any stage something that is less optimal but that was lucky. On average over many generations this effect should be removed, because the same agent won't be luck every generation, but it does mean in some environments that you will get an over-estimate of performance unless your fitness assessment is very thorough (or perhaps run separately every so many generations, to double-check). Similar concerns occur in RL too, but do not affect which agent you select for assessment or display, since there is only ever one set of agent parameters at any time.


Most suitable model for video classification with a fixed camera Consider a fixed camera that records a given area. Three things can happen in this area:

No action
People performing action A
People performing action B

I want to train a model to detect when action B happens. A human observer could typically recognize action B even with a single frame, but it would be much easier with a short video (a few seconds at low FPS).

What are the most suitable models for this task? I read this paper where different types of fusion are performed in order to feed different frames to a CNN. Are there better alternatives?

It seems you need a spatio-temporal model to learn human-body detection and action.
With regards to interesting papers on the subject I would recommand to look at Vicky Kalogeiton web site.

Her PhD thesis
2017, V. Kalogeiton, Localizing spatially and temporally objects and actions in videos,

basically cover her 3 papers on the subject:

2016, Kalogeiton, V., Schmid, C., and Ferrari, V. Analysing domain shift factors between videos and images for object detection,
[2017a, Kalogeiton, V., Weinzaepfel, P., Ferrari, V., and Schmid, C. Action tubelet detector for spatio-temporal action localization]Kalogeiton 2017a,
2017b, Kalogeiton, V., Weinzaepfel, P., Ferrari, V., and Schmid, C. Joint learning of object and action detectors

summary of Kalogeiton's PhD introduction .

Introduce an end-to-end multitask objective that jointly learns object-action relationships.
The action-object detector leverages the temporal continuity of videos.

Though intra class variations are key and appears as spatial location accuracy, appearance diversity, image quality, aspect distribution, and object size and camera framing.
Actions class refers to an atomic class such as jump, walk, run, climb, etc.

The detector builds anchor cuboids named tubelets and defined as sequences of bounding boxes with associated scores. The action detection spans over a period of time (first and last video frame detected) and takes place at a specific location in each frame. Intra frame action detection can be ambigous. On the other way a sequence bears more information (across class similarities) than a single frame to infer action.

Most previous work uses per-frame object detections, and then leverage the motion of objects to refine their spatial localization or improve their classification.

Contributions

differences between still and video frames for training and testing an object detector among which (see Chapter 3 for more details ):

spatial location accuracy,
appearance diversity,
image quality,
aspect distribution,
camera framing

jointly detect object-action instances in uncontrolled videos using an end-to-end two stream network architecture (see chapter 4 for more details )
propose the ACtion Tubelet detector (ACT-detector), which takes as input a sequence of frames and outputs tubelets, i.e. sequences of bounding boxes with associated scores (see chapter 5 for more details).


How to explain peak in training history of a convolutional neural network? I am training a simple convolutional neural network to recognize two types of 1024-point frequency spectra (FFT). This is the model I'm using:

cnn = Sequential()
cnn.add(Conv1D(filters=64, kernel_size=3, activation=LeakyReLU(), input_shape=(nInput,1)))
cnn.add(Conv1D(filters=64, kernel_size=3, activation=LeakyReLU()))
cnn.add(MaxPooling1D(pool_size=2))
cnn.add(Flatten())
cnn.add(Dense(nFinalDense, activation=LeakyReLU()))
cnn.add(Dense(nOutput, activation='sigmoid'))

However I get the following accuracy and loss during training:

Why do I get the large peak in both plots? How can it be explained? Is there a problem with the data I'm using (I mention that I obtain a similar peak when training an autoencoder for denoising using the same data)?

I found that the peak was caused by the data I am using. Specifically, the MinMaxScaler changed the data shape and I resolved the issue by simply dividing to the max value.


Is the bias supposed to be updated in the perceptron learning algorithm? I am using the following perceptron formula $\text{step}\left(\sum(w_ix_i)-\theta \right)$.

Is $\theta$ supposed to be updated in a perceptron, like the weights $w_i$? If so, what is the formula for this?

I'm trying to make the perceptron learn AND and OR, but without updating $\theta$, I don't feel like it's possible to learn the case where both inputs are $0$. They will, of course, be independent of the weights, and therefore the output will be $\text{step}(-\theta)$, meaning $\theta$ (which has a random value) alone will determine the output.

I found the answer to my question.

Treat $\theta$ as a normal weight, associated with an input that always equals $-1$.


How to train a model to predict the number of people at a certain bus stop before they cumulate in large numbers? Each person probably uses an app that tracks his/her position periodically and sends it to our servers. What I want is to use these data to train a model to predict the rush hours of each bus-stop on the map, so we can send extra buses to handle the predicted cumulation before it happens.
I have no experience in AI nor machine learning. So, which model should I use to do this?

Maybe you can use a recurrent neural network on saved data to train a predictive model based on past data.


Three step threshold in Facenet model of face recogniton Suppose i trained the images of two people say Bob , Thomas .When i run the algorithm to detect the face of a totally different person from these two say John , then John is recognized as Bob or Thomas.How to avoid this ?

I am studying a face recognition model on GitHub(link) which uses Facenet model. Problem is when an unknown image (the image which is not in training data set) is given to identify , it identifies the unknown person as one the person in the data set .I searched on web and i found i need to increase threshold value .I guess i need to increase the threshold. But when i am increasing the threshold value to 0.99,0.99,99 then only it is rejecting the unknown image (image of the person who is not in data set) and sometimes even rejecting the image of person who is in dataset.

I guess by increasing the threshold value what we are assuring is that an image is classified as one of the person in training data only when they are close enough.

How to make changes so that the model works properly ?And can someone explain Threshold in Facenet model better.

The problem originated because of the nature of the code.

Code:
https://github.com/AISangam/Facenet-Real-time-face-recognition-using-deep-learning-Tensorflow/blob/master/classifier.py

                model = SVC(kernel='linear', probability=True)
                model.fit(emb_array, label)

                class_names = [cls.name.replace('_', ' ') for cls in img_data]

As you see the code uses a SVC (Support Vector Classifier) to classify the classes. The SVC (or SVM) does not have an extra class for unknown class.

For the threshold variable, it is used in face detection, aka drawing a bounding box around the face for FaceNet to classify it.

Code:

https://github.com/AISangam/Facenet-Real-time-face-recognition-using-deep-learning-Tensorflow/blob/master/identify_face_image.py

            frame = frame[:, :, 0:3]
            bounding_boxes, _ = detect_face.detect_face(frame, minsize, pnet, rnet, onet, threshold, factor)
            nrof_faces = bounding_boxes.shape[0]

As you can see, the threshold variable is only used in detecting the bounding box.

Code for getting class name:

predictions = model.predict_proba(emb_array)
                    print(predictions)
                    best_class_indices = np.argmax(predictions, axis=1)
                    # print(best_class_indices)
                    best_class_probabilities = predictions[np.arange(len(best_class_indices)), best_class_indices]
                    print(best_class_probabilities)
                    cv2.rectangle(frame, (bb[i][0], bb[i][1]), (bb[i][2], bb[i][3]), (0, 255, 0), 2)    #boxing face

                    #plot result idx under box
                    text_x = bb[i][0]
                    text_y = bb[i][3] + 20
                    print('Result Indices: ', best_class_indices[0])
                    print(HumanNames)

You can see that no unknown class can be found.

Solution

You can try adding another threshold value and check if the predictions maximum value is lower than the threshold value. I have little experience in tensor flow so this is just a proof of concept, not sure if it will work.

best_class_probabilities = predictions[np.arange(len(best_class_indices)), best_class_indices] #original code
if(best_class_probabilities < threshold_2):
    best_class_indices = -1
HumanNames = "unknown"

By the way, because of the nature of triplet loss, you don't have to add and extra class to the SVC/SVM as the embedding model is locked and not trained, so unknown class embeddings will be very different to the known class. However you can try either approach.

Hope it can help you can have a nice day!


What are the latest methods to train a chat bot? I would like to train a bot that uses text input, memorizes a few categories and answers questions accordingly. In addition as version 2.0, I want to make the bot to answer voice inputs as well. Which are the latest machine learning/AI algorithms available for the same? Please let me know.

Your question is incredibly broad -- so in response, two broad frameworks I'd encourage you to look at are:

For cutting edge chatbot conversation development http://rasa.ai is an open source framework that is more adaptable than more traditional rule-based systems
For speech recognition check out https://discourse.mozilla.org/c/deep-speech that is also open source.


Could the normalisation of the inputs make the neural network insensitive to changes in the inputs? When using neural networks (NNs), we often normalized the inputs. I think this is done to equally capture the changes in any input feature, that is, if any feature takes huge values and other features take small values, we don't want the NN not to be able to "see" the change in the smaller value.
However, what if we cause the NN to become insensitive to the input, that is, the NN is not able to identify changes in the input because the changes are too small?

When using neural networks (NNs), we often normalized the inputs. I
think this is done to equally capture the changes in any input
feature, that is, if any feature takes huge values and other features
take small values, we don't want the NN not to be able to "see" the change
in the smaller value.
However, what if we cause the NN to become insensitive to the input,
that is, the NN is not able to identify changes in the input
because the changes are too small?

We don't normalize the input to make the model less sensitive to small changes in the input (theoretically, given the correct optimization strategy, the model will learn to approximate the smaller-ranged input as well).
An example of this would be Convolutional Neural Networks. Traditionally, images were represented with integer values ranging from $0$ to $255$. This means that a given pixel could have only $256$ distinct values. However, assuming we normalize the input, let's say to $[0, 1]$, this gives the pixel a whole range of values to occupy, making the input more sensitive to changes.
Instead, normalization is done to help with the model's convergence.


Understanding arrangement of applying filters to input channels I was watching a video about Convolutional Neural Networks: https://www.youtube.com/watch?v=SQ67NBCLV98. What I'm confused about is the arrangement of applying the filters' channels to the input image or even to the output of a previous layer.
Question 1 - Looking at the visual explanation example of how one filter with 3 channels is applied to the input image (with 3 channels), so that each 1 filter channel is applied to its corresponding input channel: .
So hence the output is 3 channels. Makes sense.
However, looking at the second screenshot which shows an example of the VGG network: , looking at the first layer (I've delineated with a red frame), which is 64 channels, where the input of the image contains 3 channels. How does the output shape become 64? The only way I would think this would be possible is if you apply:

filter channel 1 to image channel 1
filter channel 2 to image channel 2
filter channel 3 to image channel 3
filter channel 4 to image channel 1
filter channel 5 to image channel 2
filter channel 6 to image channel 3

.. and so on.
Or the other thing could be, that these are representing Conv layers, with 64 filters. Rather than a filter with 64 channels. And that's precisely what I'm confused about here. In all the popular Convolutional networks, when we see these big numbers - 64, 128, 256 ... etc, are these Conv layers with 64 filters, or are they individual filters with 64 channels each?
Question 2 - Referring back to the second screenshot, the layer I've delineated with blue frame (3x3x128). This Conv layer, as I understand, takes the output of 64 Max-pooled nodes and applies 128 Conv filters. But how does the output become 128. If we apply each filter to each Max-pooled output node, that's 64 x 128 = 8192 channels or nodes in output shape. Clearly that's not what's happening and so I'm definitely missing something here. So, how does 128 filters is applied to 64 output nodes in a way so that the output is still 128? What's the arrangement?
Many thanks in advance.

Ok, here's the break down:

The depth of an input to a convolutional layer is termed channels. The depth of a convolutional layer is the number of kernels (aka filters). The depth of a kernel is equal to the number of channels in the input.

See below:

The input (of 7x7, pad of 1) has 3 channels. The convolutional layer has 2 kernels (or filters). Each filter has a depth of 3, equal to the number of channels in the input. Using the notation you used in your question:

Filter 1, channel 1 to input channel 1
Filter 1, channel 2 to input channel 2
Filter 1, channel 3 to input channel 3
Sum all three channels of filter 1, then add bias
Filter 2, channel 1 to input channel 1
Filter 2, channel 2 to input channel 2
Filter 2, channel 3 to input channel 3
Sum all three channels of filter 2, then add bias

These steps are repeated for each frame the filter slides over the input image.

To answer question 2, if the output is 128, that simply means there are 128 filters. There could be an infinite number of filters if you so choose.

EDIT:

Here's the link to the interactive graphic: http://cs231n.github.io/convolutional-networks/


How to identify if 2 faces contain the same person? I have got numerous frames and I've detected all the faces in all the frames using Retinaface. However I need to track the faces of people over frames.
For this purpose, I assumed I could try finding the landmarks from the face using libraries like dlib and maybe compare these landmarks to check if they are infact the face of the same person.
I would like to know if there are other methods or some useful resources I could refer for the same. Thanks a lot in advance.

The topic of your problem is person re-identification. You can check here.


Can I provide a CNN with hints? Let's say I want to classify a dataset of handwritten digits (CNNs on their own can get 99.7% on the MNIST dataset but let's pretend they can only get 90% for the sake of this question).

Now, I already have some classical computer vision techniques which might be able to give me a clue. For instance, I can count the intersection points of the pen stroke

1,2,3,5,7 will usually have no intersection points
6,9 will usually have one intersection point each
4,8 will usually have two intersection points each (usually a 4-way crossover yields two intersection points which are close together)

So if I generate some meta-data telling me how many intersection points each sample has, how can I feed that into the CNN training so that it can take advantage of that knowledge?

My best guess is to slot it into the last fully connected layer just before classification.

"Distilling the Knowledge in a Neural Network" by G. Hinton et al.
https://arxiv.org/abs/1503.02531


Was the corruption of Microsoft's "Tay" chatbot an example of catastrophic forgetting? Tay was a chatbot, who learned from Twitter users.

  Microsoft's AI fam from the internet that's got zero chill. The more you talk the smarter Tay gets. — Twitter tagline.

Microsoft trained the AI to have a basic ability to communicate, and taught it a few jokes from hired comedians before setting it lose to learn from its conversations.

This was a mistake.

But why did Tay go so wrong? Was this an example of catastrophic forgetting, where short, recent trends override large, less recent training, or was it something else entirely?

Looking at what happened, it was something similar. Though, the case differs in my eyes from one perspective: if it could only do a few comedy jokes, that probably is not a profound starting point to excel in Twitter.

Firstly, Twitter is about real life, not about comedy. Discussions are sometimes tough and you easily end up to Social Media Bubbles, where only a certain kind of speaking style and topics is cultivated. So, even humans get on the wrong track there; why not a newbie bot? And, with jokes you would probably catch something about language itself, but not about the topics. So, becoming a jerk instead of a nice comedian is a logical direction, where the bot even has to go, at least a little, to communicate on same level, and not alone.

The comedian dataset compared to a Twitter dataset is also very small in a technical sense, so talking about a mini trend overkilling a megatrend in this case is probably not true, because of amounts of examples available.

So, catastrophic things happened in learning, but not catastrophic learning with the definition of that term.


Will AI always depend on models and thus approximations? In section 3 of the paper The Limits of Correctness (1985) Brian Cantwell Smith writes

  When you design and build a computer system, you first formulate a model of the problem you want it to solve, and then construct the computer program in its terms.

He then writes

  computers have a special dependence on these models: you write an explicit description of the model down inside the computer, in the form of a set
  of rules or what are called representations - essentially linguistic formulae encoding, in the terms of the model, the facts and data
  thought to be relevant to the system's behavior. It is with respect to these representations that computer systems work. In fact, that's really what computers are (and how they differ from other machines): they run by manipulating representations, and representations are always formulated
  in terms of models. This can all be summarized in a slogan: no computation without representation.

And then he says

  Models have to ignore things exactly because they view the world at a level of abstraction

He then writes in section 7

  The systems that land airplanes are hybrids - combinations of computers and people - exactly because the unforeseeable happens, and because what
  happens is in part the result of human action, requiring human interpretation

As quoted above, computers depend on models, which are abstractions (i.e. they ignore a lot of details), which are written inside the computer. Therefore, the true world cannot really be encoded into an algorithm, but only an abstraction and thus simplification of the world can.

So, will AI always depend on models and thus approximations? Can it get rid of or overcome this limitation?

There's a neuroscience theory, known as predictive coding, which roughly states that the (human) brain is constantly generating and updating a model of the world.

The brain is constantly confronted with a wealth of sensory information that must be processed efficiently to facilitate appropriate reactions. One way of optimizing this processing effort is to predict incoming sensory information based on previous experience so that expected information is processed efficiently and resources can be allocated to novel or surprising information. Theoretical and computational studies led to the formulation of the predictive coding framework (Friston 2005, Hawkins and Blakeslee 2004, Mumford 1992, Rao and Ballard 1999). Predictive coding states that the brain continually generates models of the world based on context and information from memory to predict sensory input. In terms of brain processing, a predictive model is created in higher cortical areas and communicated through feedback connections to lower sensory areas. In contrast, feedforward connections process and project an error signal, i.e. the mismatch between the predicted information and the actual sensory input (Rao & Ballard, 1999). The predictive model is constantly updated according to this error signal.

This theory should not be surprising or unintuitive, given that every person possesses a slightly different perspective (or model) of the world, which is based on her (or his) personal experiences. Of course, this is just a theory, which may not be the most precise one that describes our brain, but this theory is already being validated by a number of brain imaging studies investigating predictive feedback and the processing of prediction errors.
Therefore, artificial intelligence may not be the only entity that is based on or will be limited by a model of the world. To answer your question more directly, yes, the AI will always be limited by its model and environment (e.g. hardware), in a similar way that flatlanders are limited by their 2-dimensional nature and world, but this doesn't necessarily mean we will not be able to create useful (and even sophisticated or human-like) AI systems.


Probabilistic action selection in pursuit algorithm In the Pursuit algorithm (to balance exploration and exploitation), the greedy action has a probability say $p_1$ (updated every episode) of being selected, while the rest have a probability $p_2$ (updated every episode) of being selected.

Could you please show me an example code (Python) on how to enforce such conditional probabilistic picking?

If I am understanding your question properly, you could use something like the following:

import numpy as np
p1 = 0.1
if np.random.rand() < p1:
    action = 'greedy'
else:
    action = np.random.choice(['other_policy1', 'other_policy2', 'other_policy3'])

return action


Aside from specific training sets, what distinguishes the capabilities of different AI implementations? (Disclaimer: I don't know much about ML/AI, besides some basic ideas behind it all.)
It seems like ML/AI models can often be boiled down to statistics, where certain levers (weights) get fine-tuned based on the specific input of a large set of training data.
Clearly, ML/AI models don't only distinguish themselves in their training data alone, otherwise there would not be so many improvements happening in the field all the time. My question therefore is: What does distinguish different models of the same category?
If I have an AI that completes real-life pictures that have some missing parts, and an AI that completes a painting with missing parts, what key concepts separates the two?
If I have an AI detecting text in an image, and an AI detecting... trees in an image, what key concepts separates the two?
In other words, what is stopping me from "taking" an existing implementation of a certain AI category, and just feeding it my specific training set + rewards (i.e. judgement criteria for good vs bad output), in order to solve a specific task?
In yet again other words, if I wanted to use ML/AI to build a new model for a specific task, what concepts and topics would I need to pay extra attention to? (I guess you could say I'm trying to reverse engineer the learning process of the field here. I don't have the time to properly teach myself and become an "expert", but find it all very interesting and would still like to use some of the wonderful things people have done.)

If I understand what you mean correctly then the answer is basically nothing. Fundamentlaly all ML algorithms are ding the same thing, which is to optimize some weights for a certain output (this is true even for non-parametric methods in an implict way, but lets not dive too deep here). The only differences are:

Dataset the model is trained on
Specific dimensionality of inputs and outputs to make them compatible with the input data and the output labels.
Complexity that can be expressed by the model (the number of weights and their structure in layers in the case of Neural Networks).
Changes to the optimization process (gradient clipping, regularization, ecc.)
Structural changes to the architecture that embed assumptions about the specific problem setting (e.g. 2D-Convulutions embed assumptions for images, softmax activations embeds the assumption for classification with probabilities, hidden states embed the assumptions about memory and "fogetting", ecc...)

Therefore, if you have a "similar" problem setting where you can assume that 3, 4, 5 can be the same without problems, then you can just make the appropriate changes in 2 and change the dataset (1) to get a model that works on something different.
Of course, being able to tell how "similar" a problem is to another and what possible things could be different is quite tricky and requires a lot of knowledge about the domain of Machine Learning and how every algorithm works and why.
In essence, I'm saying that in principle you could take a model and train it for a new setting with very minor and simple changes that don't require a lot of knowledge. However, without the wider knowledge on the field of ML/AI you won't be able to tell if what you are doing is ok and how well can it work in general.


Is a team of ML scientists an "intelligent agent"? I am writing about the role of machine learning scientists in developing a solution. Is there a term for the humans who do learning?
Can we call a "team of machine learning scientists with their computers working on some ML problem"   an intelligent agent? Is "cognizer" the right term? I know that "learner" is reserved for an ML algorithm. I just want a shorter term for their role in cognition, learning.

Is there a term for the humans who do [machine] learning?

Typically you will see "AI researchers" for people studying machine intelligence in general, or "data scientists" for people working with statistics or studying specific solutions in machine learning. Both those terms are used quite flexibly, and generally understood to be scientists/engineers that work on machine intelligence problems. There are also other specialisms that might apply, such as "computer vision researcher".
If you are writing only about researchers who are focused mostly on learning systems - such as new types of learning model, or the best way to train a model for some group of tasks - then "machine learning researchers" or "ML researchers" would be fine. If they are specific people, you may want to ask them directly what title they prefer, in case you accidentally misrepresent their role and work.

Can we call a "team of machine learning scientists with their computers working on some ML problem" an intelligent agent?

No. That might be confused with something that the team is working on or creating. An "intelligent agent" can be the product of specific AI research. For instance, it is reasonable to consider AlphaZero to be an "intelligent agent" (not everyone would call it that, it depends on context, but not relevant to your question).

Is "cognizer" a right term?

No. That is an obscure term meaning something like "a being that perceives or knows". No-one will naturally associate that word with a team of researchers and their computers.

I just want a shorter term for their role in cognition, learning.

I think the most usual way to do this is to describe the team, and name them. For example:

"The MIT computer science researchers are using the X1000 system to investigate  learning of abstract spaces. The MIT team said yesterday . . ."

"Professor Hilary Smith is working with a team of graduates on the Learny McLearnface framework. Smith's team have discovered that . . ."

This is the normal way that you see a research team introduced and referred in science journalism in e.g. New Scientist or Scientific American.
If you need to describe some abstract approach about a team working in general, then you can use a similar approach, naming your teams according to how you need to differentiate between them.


Is there a service that can search for answers to general questions? I was looking for an API service where I can ask it a general question (for example, when was Einstein born?) and retrieve an answer from the web.

Is there any available service to do that? Have tried Watson services, but didn't work as expected.

You can use Google

https://encrypted.google.com/search?hl=en&q=when%20was%20Einstein%20born
and parse the response.

Wolfram ALPHA is another candidate.

http://m.wolframalpha.com/input/?i=what+year+was+Einstein+born&x=0&y=0

You can parse the returned html and see "Result:" div.


Have agents that "dream" been explored in Reinforcement Learning? I was reading this article about the question "Why do we dream?" in which the author discusses dreams as a form of rehearsal for future threats, and presents it as an evolutive advantage. My question is whether this idea has been explored in the context of RL.
For example, in a competition between AIs on a shooter game, one could design an agent that, besides the behavior it has learned in a "normal" training, seeks for time in which is out of danger, to then use its computation time in the game to produce simulations that would further optimize its behavior. As the agent still needs to be somewhat aware of its environment, it could alternate between processing the environment and this kind of simulation. Note that this "in-game" simulation has an advantage with respect to the "pre-game" simulations used for training; the agent in the game experiences the behavior of the other agents, which could not have been predicted beforehand, and then simulates on top of these experiences, e.g. by slightly modifying them.
For more experienced folks, does this idea make sense? has something similar been explored?
I have absolutely no experience in the field, so I apologize if this question is poorly worded, dumb or obvious. I would appreciate suggestions on how to improve it if this is the case.

Yes, the concept of dreaming or imagining has already been explored in reinforcement learning.
For example, have a look at Metacontrol for Adaptive Imagination-Based Optimization (2017) by Jessica B. Hamrick et al., which is a paper that I gave a talk/presentation on 1-2 years ago (though I don't remember well the details anymore).
There is also a blog post about the topic Agents that imagine and plan (2017) by DeepMind, which discusses two more recent papers and also mentions Hamrick's paper.
In 2018, another related and interesting paper was also presented at NIPS, i.e. World Models, by Ha and Schmidhuber.
If you search for "imagination/dreaming in reinforcement learning" on the web, you will find more papers and articles about this interesting topic.


Using NEAT, will the child of two parent genomes always have the same structure as the more fit parent? I'm trying to implement the NEAT Algorithm using c#, based off of Kenneth O. Stanley's paper. On page 109 (12 in the pdf) it states "Matching genes are inherited randomly, whereas disjoint genes (those that do not match in the middle) and excess genes (those that do not match in the end) are inherited from the more fit parent."
Does this mean that the child will always have the exact structure that the more fit parent has? It seems like the only way the structure could differ from crossover was if the two parents were equally fit.

Yes, if you follow the original implementation the children will inherit the topology from the most fit parent.

Keep in mind that the goal is to obtain a good population, maintaining the genetic diversity high but at the same time selecting the best individuals from the population; so, in theory you are allowed to give the topology you prefer to the children.

Here there is an example of an alternative topology inheritance in which a child gets the genes that lead to an excess node while another child gets only the genes that create a new connection.


What is the dimension of my output of the form (2n + 1, 2n + 1, #filters) after a MaxPooling layer I'm trying to white board the different mechanisms behind a convolutional neural network.
I have on question regarding the dimension of my volume after using a max pooling layer.
Let's suppose I have a (21,21,#filtres) volume's dimension. If Max Pooling divide by 2 the height and width of my volume, what will be the dimension after the Max Pooling layer ?
If odd numbers are a problem when using max pooling layer, How do I fix it ?
Thank you !

The result from applying a max pooling layer with a stride that does not exactly fit to the input will be dependent on the implementation in your library.
Assuming stride 2, and pool size (2,2), in your case the most likely things are:

The result will round up, so you will have a feature map layer with dimensions (11, 11, num_filters) although the right edge pixels will be a max over 2 pixels in the input, and the right bottom corner will just be a copy of the right bottom corner in the input (counting from top left as $(0, 0)$)

It is an error condition for your libary.

If it is not an error, then the max pooling should still perform the task it was intended to. If important features are often at the right or bottom edge, then they may generalise slightly less well, but you probably won't notice a measurable effect.
You could experiment with different sizes of pooling, different strides, or padding the previous convolutional layer so that the max pooling fits exactly. You will have to do something like this if the library has errors when the pooling does not fit exactly. You can test your experiments using cross validation, to see if there is any measurable difference.


How does mating take place in NEAT? In the Evolving Neural Networks through Augmenting Topologies (NEAT) paper it says (p. 110):

  The entire population is then replaced by the offspring of the remaining organisms in each species.

But how does it take place? Are they paired and then mated? Could this lead to fast extinction? Or are they pair each with each other? This would lead to overpopulation very fast. How are individuals paired, in NEAT?

NEAT has a constant number of organisms in its population, which prevents overpopulation from happening.

The process of mating includes the following steps.

The worst networks from every species are removed.
All species receive a number of offsprings that they can have. This is calculated by an adjusted neural network fitness.
Offsprings for species are divided among neural networks in those species. Fitter neural networks have more offsprings.
Networks from the same species are combined and create an offspring.

Speciation prevents fast extinction.


Can a neural network learn to avoid wrong decisions using backpropagation? I studied the articles on Neural Networks and Deep Learning from Michael Nielsen and developed a simple neural network based on his examples. I understand how backpropagation works and I already taught my neural network to not only play TicTacToe but also improve his own play by learning from his own successes using backpropagation.

Going forward with my experiments, I am facing the problem, that I won't always be able to show the network good moves to use for learning (maybe because I simply don't know what is correct in a certain situation), but I might be required to show it bad moves to avoid (because some of the bad moves are obvious). Teaching the network what to do using backpropagation is easy, but I haven't found a way to teach it what to avoid using similar techniques.

Is it possible to teach simple neural networks using negative examples like this or do I need other techniques? My gut feeling says, that it might be possible to "invert" gradient descent into gradient ascent to solve this problem. Or is it more complicated than this?

What you are describing is conceptually close to adversarial training. you should read more on adversarial examples and generative adversarial networks for more information.

The idea is that there is a discriminator network, whose job is to correctly discriminate between positive and negative examples. We also have a generative network, that learns to produce "adversarial examples" that "confuses" the discriminator network. By training these two networks side by side, both networks get better at their task. But it's usually the generator network that people are more interested in.

Intuitively, the naive implementation of the method you've described (gradient ascent on incorrect examples from a network in a clean/randomly-initialized state) shouldn't work. This is because negative examples don't form a "natural class" (all triangles have 3 edges, all things that are not triangles however....)


Unable to 'learn' a rotational angle by parametrising the angle as a neural network layer I'm trying to implement a neural network that can capture the drift in a measured angle as a way of dynamic calibration. i.e, I have a reference system that may change throughout the course of the data gathering and would like to train a network layer which actually converts the drifting reference to the desired reference by updating the angle parameter.
For example: Consider the 2d case. We would have a set of 2d points $X\in \mathbb{R}^2$ and a trainable parameter called $\theta$ in the layer. The output of the layer would then be:
$$X_o = XR$$ where
$$R = \begin{bmatrix}
\cos(\theta) & -\sin(\theta) \\
\sin(\theta) & \cos(\theta)
\end{bmatrix}$$
Using Adam optimizer I then try to find the $\theta$ which transforms a given angle to the desired reference.
However, the $\theta$ value seems to fluctuate around the initial value probably because of a diverging gradient(?). How can I overcome this issue?
The code is below.
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt

class Rotation2D(tf.keras.layers.Layer):
  def __init__(self):
    super(Rotation2D, self).__init__()

  def build(self, input_shape):
    self.kernel = self.add_weight("kernel", initializer=tf.keras.initializers.Constant(90),
                                  shape=[1, 1])

  def call(self, input):
    matrix = ([[tf.cos(self.kernel[0, 0]), -tf.sin(self.kernel[0, 0])],
              [tf.sin(self.kernel[0, 0]), tf.cos(self.kernel[0, 0])]])
    return tf.matmul(input, tf.transpose(matrix))

layer = Rotation2D()

t = np.arange(0, 1000)/200.

y_in = np.array([np.sin(t), np.cos(t)]).T
y_ta = np.array([np.cos(t), np.sin(t)]).T

model = tf.keras.Sequential()
model.add(layer)

model.compile(tf.keras.optimizers.SGD(lr=1.), loss='MSE')
model.fit(y_in, y_ta, epochs=1)
for i in range(100):
  print(layer.get_weights())
  model.fit(y_in, y_ta,verbose=0, batch_size=5)
y_out = (model.predict(y_in))

fig, axes = plt.subplots(2, 1)

for i in range(2):
  ax = axes[i]

  ax.plot(y_in.T[i], label = 'input')
  ax.plot(y_ta.T[i], label = 'target')
  ax.plot(y_out.T[i], label = 'prediction')

plt.legend()

plt.show()```

There are two basic problems with your code:

The functions sin(t) and cos(t) (both in numpy and tensorflow) take radians as inputs. Seeing Constant(90) in your code, and the learning rate of 1. I'm guessing that you assume that it is in degrees - that's incorrect.

In your training data y_ta is not a rotation of y_in:
y_in = np.array([np.sin(t), np.cos(t)]).T
y_ta = np.array([np.cos(t), np.sin(t)]).T

It is a reflection about y=x diagonal. No wonder it fails to find an appropriate rotation.
I just had to change y_ta to:
  y_ta = np.array([-np.cos(t), np.sin(t)]).T

And train with more sensible learning rate:
  model.compile(tf.keras.optimizers.SGD(lr=0.1), loss='MSE')
  model.fit(y_in, y_ta, epochs=10)

To get the angle (which I then convert to degrees):
  (180 * model.layers[0].kernel[0,0].numpy() / np.pi) % 360
  > 90.00187079311581


How does batch normalisation actually work? I actually went through the Keras' batch normalization tutorial and the description there puzzled me more.
Here are some facts about batch normalization that I read recently and want a deep explanation on it.

If you froze all layers of neural networks to their random initialized weights, except for batch normalization layers, you can still get 83% accuracy on CIFAR10.

When setting the trainable layer of batch normalization to false, it will run in inference mode and will not update its mean and variance statistics.

A batch normalisation layer is like a standard FC layer but instead of learning weights and bias', you learn means and variances and scale the whole layer by said means and variances.
Fact 1:
Because it behaves just like a normal layer, and can learn, with the right structure it will learn to get a high enough accuracy.
Fact 2
Disabling learning on a batch norm layer is just like disabling learning on any other layer. It will not updated any of its parameters, and in this case the parameters are the means and variances, and so these will not be updated.


Can we just switch off a malicious artificial intelligence? Let us assume we have a general AI that can improve itself and is at least as intelligent as humans.

It has wide access to technical systems including the internet, and it can communicate with humans.

The AI could become malicious.

Can we just switch off a rouge AI?

Malware viruses are a very simple form of AI.  It is not difficult to conceive of a form of malware that A) can't be detected easily, B) is redundantly distributed across thousands of computers that occasionally connect to the internet, C) is capable of detecting some kinds of threats to itself and mutating to avoid the threats.

So, simply "turning off" a malicious AI will not always be possible.


What is Reinforcement Learning? What is the cleanest, easiest way to explain someone who is a non-STEM work colleague the concept of Reinforcement Learning? What are the main ideas behind Reinforcement Learning?

Reinforcement Learning can be explained by a few equations. However I assume that this is not what you are looking at since the explanation should be for someone having a non-STEM background. Not to say non-STEM folks are not able to understand math equations, but intuition comes easier with words and examples in my opinion.

Reinforcement Learning is about learning an optimal behavior by
repeatedly executing actions, observing the feedback from the
environment and adapting future actions based on that feedback.

Let's break down the last sentence by the concrete example of learning how to play chess:
Imagine you sit in front of a chess board, not knowing how to play. The optimal behavior you'd like to learn is what moves to execute in order to win the game. So you start learning the game by playing a few moves (actions) with some figures and observing what is happening on the board (environment) and identifying which moves bring you closer victory or give you a better position on the board (feedback). Therefore in future games you will prefer moves which gave you a positive outcome in previous games.
Admittedly this is a very slow process of learning if you don't have a teacher which helps you in the beginning and you would have to play a lot of games until your first victory. But this essentially how computers (and sometimes humans in some sense) learn to do certain things by Reinforcement Learning. Behaviors which lead to positive experiences are collected, memorized and thus reinforced.


Are there well-established ways of mixing different inputs (e.g. image and numbers)? I am interested in the possibility of having extra input along with the main data. For instance, a medical application that would rely mostly on an image: how could one also account for sex, age, etc.?

It is certainly possible to put the output of a CNN and other data into, say, a densely connected network; but it seems inefficient. Are there well-established ways of doing something like this?

A more efficient way would be creating a multi input model, with something like this:

___________    _____________
|__Image__|    |Other input|
_____|_____     _____|_____
|___CNN___|     |__Dense___|
_____|______    _____|______
|_Features1_|   |_Features2_|
         __|_____|__
         |__Merge___|
         _____|______
         |___Dense__|
         _____|_____
         |__Output__|

However, you could also combine the unstructured data to the image, as stated in the quora answer:

  The out-of-the-box method:

  If you want to just take your CNN library and use it without much
  thought, there's an easy way to do it.

  Your image has “channels”: red blue and green channels, for example.
  Just add another channel for each unstructured feature. Those channels
  will just be 2D-arrays whose entries are all the same value: the value
  of your outside feature.

  It means more memory and more parameters though. If you have a lot of
  unstructured data, this can become prohibitively expensive.

  The more efficient method (and still not hard):

  You use one or more deconvolutional filters to bring the unstructured
  data up to the size of the structured data, concatenate them along the
  channel dimension, and keep going as if nothing happened.

Source: How can l train a CNN with extra features other than the pixels? (Quora)


How to show Sauer's Lemma when the inequalities are strict or they are equalities? I have the following homework.

  We proved Sauer's lemma by proving that for every class $H$ of ﬁnite VC-dimension $d$, and every subset $A$ of the domain,

  $$
\left|\mathcal{H}_{A}\right| \leq |\{B \subseteq A: \mathcal{H} \text { shatters } B\} | \leq \sum_{i=0}^{d}\left(\begin{array}{c}{|A|} \\ {i}\end{array}\right)
$$

  Show that there are cases in which the previous two inequalities are strict (namely, the $\leq$ can be replaced by $<$) and cases in which they can be replaced by equalities. Demonstrate all four combinations of $=$ and $<$.

How can I solve this problem?

I am not good with math notations so I'll stick to language more.

The first equality holds when all hypotheses shattering a set of certain dimension (whose superset has not been shattered) are non overlapping with other hypotheses shattering similar sets.

Informally let' see with an example what this means. Let's say $\mathcal H = \{h_1, h_2,h_3, h_4, h_5, h_6\}$ and all have unique behaviours on $A$ which implies $|\mathcal H_A| = |\mathcal H|$. Now if $\{h_1, h_2,h_3, h_4\}$ shatters a subset $B_1$ of size $2$ then it also shatters all subsets of $B_1$ and number of subsets including $B_1$ itself of $B_1$ is $2^{|B_1|} = 4$ (in this case). Similarly, $\{h_5 h_6\}$ must shatter another subset $B_2$ with size $=1$ and using similar argument as before we get subsets $=2$. Which shows $2+4=6$ (i.e $B_1$ and $B_2$ and all its subsets form the RHS of the equation whose total number is $6$).

NOTE: This will also hold true for hypothesis having same behaviour on subset $A$ i.e if another hypothesis $h_7$ exist which give same output on $A$ as $h_6$. There will be no effect since the former derivation is based on $\mathcal H_A$ and not $\mathcal H$

The case during which $|\mathcal H_A| < |\{B \subseteq A: \mathcal{H} \text { shatters } B\} |$ , is when we have overlapping hypothesis i.e if certain hypothesis exists which helps in shattering $2$ different subsets none of which is subset of each other. Which means now if  $\{h_1, h_2,h_3, h_4\}$ shatters some $B_1$ and $\{h_4, h_5\}$ with the overlap of $h_4$ shatters another hypothesis then this is the case $<$ will hold.

Now coming to the second part of the equation, we can see equality will hold when the hypothesis shatters all possible subsets of size $\leq d$. If we define a hypothesis as a set of points where the values is $1$ and $0$ otherwise, then we can verify this. Clearly, if $\mathcal H$ shatters all sets of size $\leq d$ then we can pick any set of size $i \leq d$, and total number of such sets will be $\sum_{i=0}^d \begin{array}{c}{|A|} \\ {i}\end{array}$. In all other cases $<$ will hold.

NOTE: A hypothesis class having VC dimension $d$ does not necessarily shatter all sets of size less $\leq d$ and hence the inequality. Check tis answer.

You can now play with the different scenarios to get $4$ cases as required, and as can  be clearly seen the assumptions for equality in both the part of the equations are independent of each other. One deals with overlapping behaviour, while other deals with shattering of subsets $\leq d$. But note only under a certain condition will the equality hold on both sides, namely the hypothesis class shatters all possible subsets of size $d$ non overlappingly.

Sidenote: The first part of the equation can probably be proven by formal number theory, but I am not sure how.