text:
Best approach for 2D Grid Image Segmentation
I'm working on a project where I need to extract text from grocery discount flyers like the Costco announcement below (retrieved in a random google search, Costco is not the deal here):

If I just run OCR (like with Tesseract in python):
import cv2
import pytesseract
img = cv2.imread('costco.jpg')
text = pytesseract.image_to_string(img)
print(text)

I get:

Cadbury Chocolate
variety pack packet
ere $12.99 i rom hagst 31026 2012
>
> Je laa
> + a
>
> Wrigley’s Excel Gum variety
>
> Backol 24
>
> $13.79 fom agus 26.202
OFF
Solon Extra virgin olive oil [...]

Which is a lot noisy.
My guess is that splitting the image to its base squares enchances the recognition.
However, I'm confused on how to do it. I can classify images using a CNN, but am not sure about object recognition.
Should I have a sliding window and train several "grid box" objects on a generic CNN and then provide this window data to be classified? How to adapt to distinct object window sizes?

This is a really cool problem. You already have a working model here are a few different ways of going forward with the project.

Grouping text based on locality. "no segmentation"  Text region extraction in a document image based on the Delaunay tessellation
Segmentation  Multiscale Edge-Based Text Extraction from Complex Images
Training a map of the image then extracting text form the map.  Multi Oriented Text Detection

Training the model to detect boxes followed by extracting the text from each box seems like a very smart direction to move in. This paper talks about the former.  automatic image segmentation and edge detection  Good luck!

Thank you for the directions! I'll look at them and return the check answer as soon as I've figured it out.

authors: Дмитрий Курков


text:
Why embedding layer is used in the character-level Natural Language Processing models
Problem Background
I am working with a problem, which requires a character-level, deep learning model. Previously I was working with word-level deep NLP (Natural Language Processing) models, and in these models almost always embedding encoding was used to represent given word in a lower-dimensional vector form. Furthermore, such embedding encoding allowed for putting similar words near themselves in the new lower-dimensional vector representation (i.e. man and woman vectors were near themselves in the vector space) which improved learning. Nevertheless, I often see that people use embedding encoding in character level NLP models. Even if the character-level one-hot encoding vectors are quite small in comparison to word-level one-hot encoding vectors (about 36 to 32k rows). Furthermore, there is no much correlation between characters, there is no something like "similar characters" in comparison to similar words, therefore some characters in comparison to other shouldn't be put near themselves.
Question
Why embedding encoding is used in the character-level NLP models?

source: Stack Exchange

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

sort: votes


text:
How should I make output layer of my neural network so that I can get outputs ranging from [-20,-1]
I am trying to make a neural network which takes in 0 and 1 as it's input and should give me output ranging from [-20,-1].I am using three layers with sigmoid as the activation function .How should I design my output layer?Any sort of code snippet from your side will be helpful .I am using tensorflow.Please help me out with the same

You can use $tanh$ function as the activation for the output and then the result would be $y = 9.5 \cdot tanh(x) - 10.5$. That way when $tanh$ gives output $1$ , $y$ would be $-1$ and when $tanh$ gives $-1$ output would be $-20$ and anything  in $[-1, 1]$ would be in $[-20, -1]$.

Thanks.:)..I just tried adding it but still my network is not learning at all.

Try using MinMaxScaler to normalize target values. And then you can use the inverse transform of the output after training.

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


text:
Plot class activation heatmap of Caffe Model in Python
Given the following 3 research papers, the authors have shown different heatmap graphical representations for features of the trained CNN models:

On the performance of Convnet feature for place recognition: link

NetVLAD: CNN architecture for weakly supervised place recognition: link

Deep Learning Features at Scale for Visual Place Recognition: link

Does anyone know the easiest heatmap implementation in Python given deploy.protxt and model_wights_bias.caffemodel files?
PS: I am aware of the following answers and packages: answer1, package1 but they do not provide these solutions shown in figures above!
Thanks,


text:
What could I do to this CNN to achieve a higher accuracy on the cifar10 dataset?
I have achieved around 85% accuracy using the following architecture:

I used a learning rate of 0.001 and trained the model over 125 epochs with a batch size of 64.
Any suggestions would be much appreciated. Thanks in advance.

Try applying a grid search to all your hyper parameters (such as dropout and learning rate). A grid search is easy to do and can improve your accuracy a lot. If you really wanted to know the best architecture, search up NAS (Neural Architecture Search). Keep in mind this is significantly more complicated.

You results show signs of overfitting at around epoch 40. In order to overcome this you can either simplify the model somewhat or increase regularization. You do not share what values you are using for dropout regularization so you can try increasing that.
But to be honest, I am not sure if that is going to help. You are using dropout in a pure CNN architecture, which I do not see that often in recent models. When they exists, they are usually at the very end of the network, or after densely connected layers. There are claims that regular dropout does not work as intended for convolutional layers, so the idea of spatial dropout is developed.
But you are using them after pooling layers and such a design may not be as bad as using them after convolutional layers. In any case, if you check the top performers on this dataset, you can see there are some who are trying to come up with new regularization techniques for CNN's, such as shake-shake, shakedrop and cutout.
However, given you already have an overfitting model, removing regularization might not be the best idea. But if you replace the layers after (and including) the last convolution with some fully connected layers, you can use dropout regularization on them instead. This would remove the largest convolutional layer of the model and you can add dense layers without increasing model size.
For image recognition tasks of any kind, easiest way to achieve high accuracy is via transfer learning.


text:
Same implementation, but agent is not learning in Retro Pong Environment
I tried to implement the exact same python coding by Andrej Karpathy to train RL agent to play Pong, except that I migrated the environment from Gym to Retro.
Everything is the same except the action space in Retro is in indices and not in discrete as in Gym. The index has a size of 8, and index 4 and 5 are actions to move up and down.
But why the little modification has caused the agent not learning at all with running reward at -20 after over 3,000 episodes?
I have checked the frame pre-processing before input to the policy forward neural network and it seems to be normal.
As far as I know, the output from the neural network is the probability of the paddle to move upwards. So I checked it. After few thousands episodes, the probability of the agent to move up just maintained at 0.5.
I know the problem exists between the pre-processing and policy forward neural network, but I just cannot locate the problem. Appreciate if someone could help.
The whole coding is as follow:
import retro
import numpy as np
import _pickle as pickle

H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.98 # discount factor for reward
decay_rate = 0.98 # decay factor for RMSProp leaky sum of grad^2
resume = False # resume from previous checkpoint?
render = True

# model initialization
D = 80 * 80 # input dimensionality: 80x80 grid
if resume:
  model = pickle.load(open('save.p', 'rb'))
else:
  model = {}
  model['W1'] = np.random.randn(H,D) / np.sqrt(D) # "Xavier" initialization
  model['W2'] = np.random.randn(H) / np.sqrt(H)

grad_buffer = { k : np.zeros_like(v) for k,v in model.items() } # update buffers that add up gradients over a batch
rmsprop_cache = { k : np.zeros_like(v) for k,v in model.items() } # rmsprop memory

def sigmoid(x):
  return 1.0 / (1.0 + np.exp(-x)) # sigmoid "squashing" function to interval [0,1]

def prepro(I):
  """ prepro 210x160x3 uint8 frame into 6400 (80x80) 1D float vector """
  I = I[35:195] # crop
  I = I[::2,::2,0] # downsample by factor of 2
  I[I == 144] = 0 # erase background (background type 1)
  I[I == 109] = 0 # erase background (background type 2)
  I[I != 0] = 1 # everything else (paddles, ball) just set to 1
  return I.astype(np.float).ravel()

def discount_rewards(r):
  """ take 1D float array of rewards and compute discounted reward """
  discounted_r = np.zeros_like(r)
  running_add = 0
  for t in reversed(range(0, r.size)):
    if r[t] != 0: running_add = 0 # reset the sum, since this was a game boundary (pong specific!)
    running_add = running_add * gamma + r[t]
    discounted_r[t] = running_add
  return discounted_r

def policy_forward(x):
  h = np.dot(model['W1'], x)
  h[h<0] = 0 # ReLU nonlinearity
  logp = np.dot(model['W2'], h)
  p = sigmoid(logp)
  return p, h # return probability of taking action 2, and hidden state

def policy_backward(eph, epdlogp):
  """ backward pass. (eph is array of intermediate hidden states) """
  dW2 = np.dot(eph.T, epdlogp).ravel()
  dh = np.outer(epdlogp, model['W2'])
  dh[eph <= 0] = 0 # backpro prelu
  dW1 = np.dot(dh.T, epx)
  return {'W1':dW1, 'W2':dW2}

env=retro.make(game='Pong-Atari2600',players=1)
observation = env.reset()
prev_x = None # used in computing the difference frame
xs,hs,dlogps,drs = [],[],[],[]
running_reward = None
reward_sum = 0
episode_number = 0

while True:
  if render: env.render()

  action=[0,0,0,0,0,0,0,0] #reset the rl action
  # preprocess the observation, set input to network to be difference image
  cur_x = prepro(observation)
  x = cur_x - prev_x if prev_x is not None else np.zeros(D)
  prev_x = cur_x

  # forward the policy network and sample an action from the returned probability
  aprob, h = policy_forward(x)

  rlaction = 4  if np.random.uniform() < aprob else 5 # roll the dice!
  # record various intermediates (needed later for backprop)
  xs.append(x) # observation
  hs.append(h) # hidden state
  y = 1 if rlaction == 4 else 0 # a "fake label"
  dlogps.append(y - aprob) # grad that encourages the action that was taken to be taken (see http://cs231n.github.io/neural-networks-2/#losses if confused)
  action[rlaction]=1
  # step the environment and get new measurements
  observation, reward, done, info = env.step(action)
  reward_sum += reward
  drs.append(reward) # record reward (has to be done after we call step() to get reward for previous action)

  if done: # an episode finished

    episode_number += 1

    # stack together all inputs, hidden states, action gradients, and rewards for this episode
    epx = np.vstack(xs)
    eph = np.vstack(hs)
    epdlogp = np.vstack(dlogps)
    epr = np.vstack(drs)
    xs,hs,dlogps,drs = [],[],[],[] # reset array memory

    # compute the discounted reward backwards through time
    discounted_epr = discount_rewards(epr)
    # standardize the rewards to be unit normal (helps control the gradient estimator variance)
    discounted_epr -= np.mean(discounted_epr)
    discounted_epr /= np.std(discounted_epr)

    epdlogp *= discounted_epr # modulate the gradient with advantage (PG magic happens right here.)
    grad = policy_backward(eph, epdlogp)
    for k in model: grad_buffer[k] += grad[k] # accumulate grad over batch

    # perform rmsprop parameter update every batch_size episodes
    if episode_number % batch_size == 0:
      for k,v in model.items():
        g = grad_buffer[k] # gradient
        rmsprop_cache[k] = decay_rate * rmsprop_cache[k] + (1 - decay_rate) * g**2
        model[k] += learning_rate * g / (np.sqrt(rmsprop_cache[k]) + 1e-5)
        grad_buffer[k] = np.zeros_like(v) # reset batch gradient buffer

    # boring book-keeping
    running_reward = reward_sum if running_reward is None else running_reward * 0.99 + reward_sum * 0.01
    print(('%d , %d , %f ') % (episode_number-1,reward_sum,running_reward))
    if episode_number % 20 == 0: pickle.dump(model, open('save.p', 'wb'))
    reward_sum = 0
    observation = env.reset() # reset env
    prev_x = None

Welcome to SE:AI!  This question has been flagged as out-of-scope.  Could you potentially revise to make it about the underlying theoretical aspects, in addition to the specific problem you're trying to identify in the code?


text:
Reduce same sample distance in VAE encodings
I'm working on a beta VAE model learning a latent representation used as a similarity metric for image registration.
One of the main problems I'm facing is that the encoder + sampler output doesn't fulfill the requirements for a mathematical metric (https://en.wikipedia.org/wiki/Metric_(mathematics)) - is there a known way of how to decrease same-sample distance after encoding + sampling as well as promoting transitivity (triangle inequality) and symmetry?

"One of the main problems I'm facing is that the encoder + sampler output doesn't fulfill the requirements for a mathematical metric", isn't the output just a number or vector? Can you be more specific: why can't the output of the encoder or decoder be used by a metric?

The distance between samples drawn from the distribution defined by the encoded input isn't a metric as it doesn't fulfill the requirements of a mathematical metric as listed here:https://en.wikipedia.org/wiki/Metric_(mathematics)
I would like to transform the model in such a way that this is possible, or would like to dinf out about any other options to achieve the same effect.

You're not specifying which metric you are using. You could be using the Euclidean metric, which is a metric.

If I have a "function" g(x) for which g(x) = g(x) doesn't hold, because it includes a random process like sampling, then f(g(x)) is not necessarily a metric with regards to x even if f is a metric. If g is a function drawing a random sample which depends on the input, for example it samples a uniform distribution between x-1 and x+1, then f(g(x)) is no more a metric because it could be anything from f(x-1) to f(x+1).

The metric has nothing to do with your stochastic operations. For a given arbitrary (same) $x$, then if the function $d$ satisfies the properties that make it a metric (such as $d(x, x) = 0$ if $x=x$), then it will be a metric. Of course, for different inputs, the metric may produce different results, but this is not the problem of the metric. To be clear, in your example $x_i \neq x_j$, for $i \neq j$. Then $d(x_i, x_j) > 0$. In your specific case, the inputs are, in fact, different and are different every time because they depend on a stochastic element.

Exactly, the inputs to the metric f produced by function g are different. Now my question is how I can force the encoder which approximates or computes function g to learn g in such a way that g and afterwards the concatenation with f form a metric.

You need to avoid any stochastic operation or keep track of them so that later you can compare the outputs of the encoder or decoder by taking into account the stochasticity (i.e. you remove the stochasticity element from the outputs before comparing). I don't really know if this is feasible. Maybe it also depends on your implementation of the VAE.

Well it's hard to avoid stochastic operations in a VAE since that's one of the core elements.
One solution I'm currently experimenting with is to instead of comparing the samples drawn from distributions for x and y to compare the distributions directly using a metric like symmetric KL divergence.


text:
How to organize model training hyperparameters
I am working on multiple deep learning projects, most of them in the area of computer vision. For many of them I create multiple models, try different approaches, use various model architectures. And of course I try to optimize hyperparameters for each model.
Now, that itself works fine. However, I start to lose track of all the various parameters and model layouts I tried. The problem is, sometimes for example I want to re-train a model from a past project with a new data set, but using the same hyperparameters from the last (best) successful training. So I need to look up that project's documentation, or I have some hyperparameters saved in a text or Excel file, etc.pp.
For me that feels a bit cumbersome. I bet I am not the only one facing this problem, surely there must be a better way than "remembering" all the hyperparamters from all projects / models manually via text files and alike.
What are your experiences, have you found a better software / solution / approach / best practice / workflow for that? I must admit, I would welcome a software to aid with that a lot.


text:
NLP annotation tool online and other tools to compare performances of different NLP algorithms
I do text annotations (POS tagging, NER, chunking, synset) by using a specific annotation tool for Natural Language Processing. I would like to make the same annotations on different tools to compare the performances of both.
Furthermore, for I found several logical and linguistic errors in the way the algorithm was previously trained, I would like to measure the way such anomalies affect the intelligence of the chatbot (that's to say its ability to understand questions and answers made by the customers as regard to sentences which have been structured in a certain way), by comparing results with those performed by other NLP engines.
In other terms, I would like to collect some "benchmark" to have an idea of which level the NLP algorithm developed by the company I work with works at.
Is there any tool (open source annotation tools based on other NLP algorithms, tools to collect benchmark, etc.) which might help me to perform such a task?


text:
Calculation of Neural network biases in backpropagation
While learning neural networks I've found a basic Python working example to play with. It has 3 input nodes, 4 nodes in a hidden layer, 1 output node. 5 data sets for training.
The initial code is without biases, which I'm trying to implement, forward and back calculations. From different internet sources I see that bias is just like other weights with a static input value 1, and backpropagation calculation should be similar and simplier.
But my current code version is not working - with the same input I get very different results from ~0.002 to ~0.99.
Please help me to fix biases calculations. Probably lines marked with ???. Here is a Python 2 testing code:
import numpy as np

# Sigmoid and it's derivative
def nonlin(x, deriv=False):
    if (deriv == True):
        return x*(1-x)

    return 1/(1+np.exp(-x))

X = np.array([[0,0,1],
              [0,1,1],
              [1,0,1],
              [1,1,1],
              [1,1,1]])

Y = np.array([[0],
              [1],
              [1],
              [0],
              [0]])

# Static initial hidd. layer weights for testing
wh = np.array([[-0.16258307,  0.43597283, -0.99471565, -0.39715906],
               [-0.70551921, -0.81601352, -0.62549935, -0.30959772],
               [-0.20477763,  0.07532473, -0.15920573,  0.3694664 ]])
# Static initial output layer weights for testing
wo = np.array([[-0.59572295],
               [ 0.74949506],
               [-0.95195878],
               [ 0.33625405]])

# Hidden layer's biases
biasH = 2 * np.random.random((1, 4)) - 1  # ???
# Output neuron's bias
biasO = 2 * np.random.random((1, 1)) - 1  # ???
# Static hidden layer's biases input
biasInputH = np.array([[1, 1, 1, 1]])     # ???
# Static output layer's bias input
biasInputO = np.array([[1]])              # ???

# Number of iterations to teach
for j in xrange(60000):

    # Feedforward
    h = nonlin(np.dot(X, wh) + biasH)
    o = nonlin(np.dot(h, wo) + biasO)

    # Calculate partial derivatives & errors
    o_error = Y - o

    if (j % 10000) == 0:
        print "Error:" + str(np.mean(np.abs(o_error)))

    o_delta =  o_error * nonlin(o,     deriv=True)
    o_biases = o_error * nonlin(biasO, deriv=True)  # ???

    h_error =  o_delta.dot(wo.T)
    h_delta =  h_error * nonlin(h,     deriv=True)
    h_biases = h_error * nonlin(biasH, deriv=True)  # ???

    # Update weights and biases
    wo += h.T.dot(o_delta)
    wh += X.T.dot(h_delta)

    # biasH += biasInputH.dot(h_delta)  # ???
    # biasO += biasInputO.dot(o_delta)  # ???

# Try new data
data = np.array([1,0,0])

print "weights 0:", wh
print "weights 1:", wo
print "biases 0:",  biasH
print "biases 1:",  biasO
print "input:   ",  data

h = nonlin(np.dot(data, wh))
print "hidden:  ", h
print "output:  ", nonlin(np.dot(h, wo))


text:
Formulating MCTS with random outcomes of actions?
I am working on implementing MCTS for a scheduling problem where MCTS is formulated each time there are multiple jobs that need to be scheduled. When a job is executed, the resulting state of the system is random. The challenge I'm having is that the implementation I'm currently using relies on the ability to determine if a node is fully expanded. However, there are so many children of the root node that it's not feasible to expect all of them will ever be visited. Is there a suggested method of conducting MCTS in cases where nodes will not likely ever be fully expanded?

Welcome to AI.SE @hoffee. I think you're asking how to perform MCTS when actions have non-deterministic outcomes. Is that the essence of your question, or are you trying to ask something else?

Yes, that is what I'm asking.

There is a great paper "A Survey of Monte Carlo Tree Search Methods". Read the chapter on stochastic MCTS. Short: introduce "random nodes" - fake player which do random actions.

I am aware of that paper but I will revisit that chapter, thanks for the suggestion.


text:
Troubleshooting Binary Classifier
I trained a binary classifier using ML.NET's AutoML feature on a small dataset (compared to other, similar models I've trained that seem to work well)-around 500 rows with around 50 features. AutoML used cross-validation with 5 folds.
The training data is balanced to about 200 positive cases to 300 negative cases, which isn't an unreasonable representation of the real world based on domain knowledge.
The model's metrics are poor compared to other, similar models, e.g.:

Accuracy: 0.64
Positive Precision: 0.375
Positive Recall: 0.09
Negative Precision: 0.67
Negative Recall: 0.92
F1 Score: 0.15

When the model is run against unseen data, it predicts the negative case 99% of the time.
If the accuracy were truly as stated in the metric, a correct classification 2/3 of the time has some practical value in this application. However, the actual predictions of 99% the negative case are surely flawed.
Is the training set too small to expect reasonable results? Is there anything I can do to improve the model?


text:
Finding total number of states in a POMDP
I've been working on a question that is posed in a document I've been reading, that models qualifying for a job as a POMDP. In this model, a person takes 3 exams, and must pass all of them in order to get the job. The person make either be qualified or not qualified in the subjects covered by each individual exam, and there is some probability that a person may be qualified for a subject covered in a particular exam, but still not pass (due to nerves). False passes are also possible as well.
A candidate is allowed a maximum of 2 exam attempts.
In understanding this problem, I've tried to list out all possible states the person might be in (qualified / not qualified for each exam), and have found the following possible states: (where Q is qualified, and N is not qualified)
QQQ
QQN
QNN
QNQ
NNN
NQN
NNQ
NQQ
So, the total number of possible states is 8.
Have I covered all possible states? I'm wondering if there's an easier way to find out total number of states, without having to list them all out in the above way. I'm very new to this field, so any help is appreciated.


text:
Loss function for increasing the quality of the image when labels are not perfectly alligned
I am trying to increse the quality of the images that I gather from the microscope.  That is a acoustic microscope and there are lots of technical details but in a nutshell the low quality images and its corresponding high quality images that I gather from the same sample are not perfectly alligned because in my setting it is impossible to increase quality without removing the sample from the microscope so when I put it again it is a manual process so they are not perfectly aligned.
Output of my network will be,let's say, 256 x 256 image and its corresponding label will be high quality 256 x 256 image,in theory, of the exactly same area. If I make pixel to pixel comparison between them, for example taking MSE for the loss function, will it be able to learn ? I am not sure because pixels are not perfectly alligned, they do not represent the same area of the image(the difference is not that great but they are not perfectly alligned as I said)


text:
Trying to get started with LISA and Lisp
I am trying to to do a sort of block-validator for bitcoin(and alike chains), in it I need to depending on chain and block-height only allow certain operators in the transactions scripts. One thought I had was that this might be something that LISA should be good for. (I might be wrong in this) but shouldn't something like a rule engine be a good fit for that? What I want is a good way to defines the rules for my validator on how to validate that a block and its transactions adhere to the consensus rules?
I am sort of getting to this point
(defpackage #:chain-validator
  (:shadowing-import-from #:lisa #:assert)
  (:use #:lisa
    #:cl))

(in-package :chain-validator)

(defclass chain-fundamental () ())

(defclass chain-block (chain-fundamental)
  ((height :initarg :height :initform 1)
   (chain :initarg :chain :initform :bitcoin)))

(defclass chain-tx (chain-fundamental)
  ((in-block :initarg :block :initform 'nil)
   (pk-script :initarg :pk-script)
   (is-coinbase-tx :initarg :coinbase :initform 'f)))

(defclass chain-OP (chain-fundamental)
  ((name :initarg :name)
   (op-code :initarg :op-code)))

(defrule dont-allow-op-mul-after-height-1000
    ;;; how to write this one?????
    ;; but if I only want to allow mul on a certain chain after height
    ;; 2000?
    )

(defrule startup ()
  =>
  (assert-instance
   (make-instance 'chain-OP :name :PUSHDATA4 :op-code #x4e))
  (assert-instance
   (make-instance 'chain-OP :name :EQUAL :op-code #x87))
  (assert-instance
   (make-instance 'chain-OP :name :MUL :op-code #x95))
  (let* ((genesis-blk (make-instance 'chain-block))
     (later-blk (make-instance 'chain-block :height 2500))
     (first-coinbase-tx (make-instance 'chain-tx :block genesis-blk))
     (later-coinbase-tx (make-instance 'chain-tx :block later-blk)))
    (assert-instance genesis-blk)
    (assert-instance later-blk)
    (assert-instance first-coinbase-tx)
    (assert-instance later-coinbase-tx)))

;; how can I use LISA to get the chain-OPs that are allowed for a
;; transaction belonging to a specific block at some height, I sort of
;; want to find them all so i later can verify that the pk-script part
;; only contains those OPs. Could I write rules that would acctually
;; do the validation for me? that would check if chain-tx.pk-script
;; only contains certain OPs. And if we have multiple chains, how do I
;; write the rules to take account for that?

But after that I don't know how to proceed, the questions I want LISA to answer for me are things like

What are the valid script operations for a certain block, or transaction?
Is this block or transaction valid?

Maybe what I need is primer on rule engines or a good tutorial. I just can't really get my head around how to write the rules.


text:
learning object recognition of primitive shapes through transfer learning problem
Question on transfer learning object classification (MobileNet_v2 with 75% number of parameters) with my own synthetic data:
I made my own dataset of three shapes: triangles, rectangles and spheres. each category has 460 samples with diferent sizes, dimensions, different wobbles at edges. They look like this:

I want the network to classify these primitive shapes in other environments as well with different lighting/color conditions and image statistics.
Even though I'm adding random crops, scaling, and brightnesses, at training step 10 it's already at 100% training and validation accuracy. Cross entropy keeps going down though. I'm using tensorflow hub. The performance of the network in the end could be better within other environments (virtual 3d space with such shapes). Also trained and tested for ~ 50 steps to see if the network is overfitting, but that doesn't work too well.
What alterations would you  recommend to generalize better? Or shouldn't I train on synthetic data at all to learn primitive shapes? If so, any dataset recommendations?
Thanks in advance

im assuming you dont have labels on the actual data your performing inference on? Also in your case you need to make sure the augmentations cover the difference in domains

I don't necessarily have the labels there no. Any suggestions on how to make the augmentations cover the difference in domains? Thanks!


text:
What is a good model for regression problem with binary features and small data?
I am trying to predict the solution time for riddles in which matchsticks are combined into digits and operators. An example of a matchstick riddle is 4-2=8. The solution for this riddle would be obtained by moving one matchstick from the ‘8’ to the ‘-’ sign, resulting in the correct equation 4+2=6. The data consists of 100 riddles and the corresponding solution times. The two types of features that are available for each riddle are:

a 23 dimensional binary vector that indicates which of the available positions are filled with matches
or
a 12-dimensional integer vector that counts the appearance of each token (10 digits, 2 operators)

Although today neural nets are very popular I am not sure that a neural net is the best choice for this particular problem. Firstly, because the data set is very small. Secondly because of the binary inputs.  What might be a more effective model for this problem ?


text:
yolo output and how to define labels for backpropogation on it
I want to build the yolo architecture in keras but can't understand the basic idea behind the training of the yolo, like how to define the labels for whether there is no object there what we have to do. Do we have to take the boundary box as 0 or not include the block only for that part? It's quite confusing.


text:
How Euclidean distance algorithm calculate two different face images are match or not match in face recognition?
I am trying to make a face login application. face comparison algorithm is using Euclidean distance to calculate two different face images that are the same or not the same. can anyone help me with how the Euclidean distance algorithm is working?

Euclidean distance is the vector distance - https://en.wikipedia.org/wiki/Euclidean_distance - e.g. $\sqrt{\sum_i (x_i - y_i)^2}$. This seems a bit simple for a question though if you are doing face recognition work . . . could you explain more about where you are stuck

Simply put, Euclidean distance measures how far away two items are (see Neil Slater's comment).
In order to apply this to a pattern recognition task, you will need to convert the items to compare (in your case images of faces) into feature vectors (ie lists of numerical values), and then you do a pairwise comparison to work out how distant two faces are. You will then need to set a threshold where you treat two images as being the same face (typically where the distance between the feature vectors is small).
Selecting the right features is obviously crucial here. I'm not an expert on face descriptions, but it would probably be something like

the distance between the eyes
the distance between the bottom of the nose and the top of the upper lip
...

Once you have these measurements, store the values for each image in a vector and you can apply the Euclidean distance. Effectively, each image is represented as a point in the  $m$-dimensional feature space, where each measurement is a dimension. To select good features make sure they are not correlated (ie they are independent of each other) and are the same scale (eg all are distances, so not eye colour)
The choice of Euclidean distance is fairly minor: there are other distance metrics which might work equally well or even better. As I mentioned, the key point is selecting appropriate feature values.

You are describing "old school" biometric feature embeddings. Typical modern systems will learn more automated vector representation. Most importantly these can be trained without requiring labels with all the biometrics from thousands of faces. Instead to learn a feature vector they just need to know the true identity of person plus have multiple images of same person (at least 2 for each person, but more can be better). Otherwise the Euclidean distance part is the same

@NeilSlater Yes, you are right; but for a simple project (which I assume the OP is talking about) it's easier to do it that way.


text:
Unable to train Coach for Banana-v0 Gym environment
I have just started playing with Reinforcement learning and starting from the basics I'm trying to figure out how to solve Banana Gym with coach.
Essentially Banana-v0 env represents a Banana shop that buys a banana for \$1 on day 1 and has 3 days to sell it for anywhere between \$0 and \$2, where lower price means a higher chance to sell. Reward is the sell price less the buy price. If it doesn't sell on day 3 the banana is discarded and reward is -1 (banana buy price, no sale proceeds). That's pretty simple.
Ideally the algorithm should learn to set a high price on day 1 and reducing it every day if it didn't sell.
To start I took the coach-bundled CartPole_ClippedPPO.py and CartPole_DQN.py preset files and modified them to run Banana-v0 gym.
The trouble is that I don't see any learning progress regardless what I try, even after running like 50,000 episodes. In comparison the CartPole gym successfully trains in under 500 episodes.
I would have expected some improvement after 50k episodes for such a simple task like Banana.

Is it because the Banana-v0 rewards are not predictable? I.e. whether the banana sells or not is still determined by a random number (with success chance based on the price).
Where should I take it from here? How to identify which Coach agent algorithm I should start with and try to tune it?

Which coach algorithm did you use? If it was one that worked well for CartPole, it may need to be changed to work with a new environment.

@NeilSlater I tried ClippedPPO and DQN. If it showed at least some improvement I could take it from there and try to tune it, but as I didn't observe any noticeable improvement I doubt these two are fit for Banana. Maybe some other algorithm would do better? Not sure which one to try.

It's probably not the choice of algorithm, but hyperparameters that is working against you. If I get time I will take a deeper look and try to answer.


text:
Can mobilenet in some cases perform better than inception_v3 and inception_resnet_v2?
I have implemented a multi-label image classification model where I can choose which model to use, I was surprised to find out that in my case mobilenet_v1_224 performed much better (95% Accuracy) than the inception models (around 88% Accuracy), I'm using pretrained models (that I download from here and adding a final layer that I train on my own data (3000 images). I wanted to get your opinion and see if maybe I'm doing something wrong.

it's totally possible that mobilenet can perform better than inception_resnet_v2. I don't think you're necessarily doing something wrong. One thing which I can suggest is to repeat your experiments and see if you obtain the same result.


text:
References on generalization theory and mathematical abstraction of ML concepts
I'd like to learn about generalization theory for machine learning algorithms. I'm looking for books and other references (in case books aren't available) that provide a gentle introduction to the field for a relative beginner like me.
My background includes exposure to mostly undergrad mathematics and I have enough mathematical maturity to learn graduate-level topics as well.
To be more specific, I'm looking to understand more about mathematical abstraction of ML concepts (e.g. learning algorithm, hypothesis space, complexity of algorithm/hypothesis etc.), the purpose of an ML algorithm as an expected risk minimization exercise, techniques used to get bounds on generalization and so on.
To be even more specific, I'm looking to familiarize myself with concepts, theory and techniques so that I can understand papers (at least on a basic level) like:

Generalization in Deep Learning (2019)
Quantifying the generalization error in deep learning in terms of data distribution and neural network smoothness
nbro's answer to this question

and references therein


text:
Multicamera Tracking vs Single Fisheye Camera
Suppose you want to detect objects and also track objects and people. Is it better to train a model using a single fisheye camera or using multiple cameras that mimic the view of the fisheye camera?
Also, what can be done to remove objects that are washed out? Like for very small objects, how do you make them more visible? Would multicamera tracking be better in this scenario?

Fisheye camera is always worst. Both convolutional networks object detectors and feature-based object detectors rely on the "isometry" of planar image - lack of strong distortions. Multiple camera have added benefit of several independent sources of information - ensembling. If each camera processed by separate network that may help in verification of objects by voting. With very small objects no simple methods would help. Multiple camera may help a little if all camera output processed together (stacked) as single network input, but don't hold much hope - detecting few pixel objects is very difficult, if possible at all.


text:
How can I feed any word into a neural network?
I am working on an Intent detection problem for a chatbot in Java.
So I need to convert words from String to a double[] format.
I tried using wordToVec(deeplearning4j), but it does not return a vector for words not present in the training data.
e.g. My dataset for wordToVec.train() does not contain the word "morning". So wordToVec.getWordVector("morning") returns a null value.
There is no need to find the coorelation between two words(like in word2vec), but it should be able to give me some sort of vector representation for any word.
Here are some things I thought of-

I could use a fixed length hash function and convert resulatant hash into vector.(Will Hash Collision be strong enough to be an issue in this case?)
I could initialize for each word a vector of huge length as zero, and set its elements as the ASCII value-64.
e.g. Keeping Maximum vector length as 10, AND would be represented as-
[1,14,4,0,0,0,0,0,0,0], and normalize this.
Is there a better solution to this problem?

Here is the code I used to train the model-
public static void trainModel() throws IOException
    {
        //These lines simply generate the dataset into a format readable by wordToVec
        utilities.GenRawSentences.genRaw();

        dataLocalPath = "./TrainingData/";
        String filePath = new File(dataLocalPath, "raw_sentences.txt").getAbsolutePath();
        //Data Generation ends

        SentenceIterator iter = new BasicLineIterator(filePath);
        TokenizerFactory t = new DefaultTokenizerFactory();
        t.setTokenPreProcessor(new CommonPreprocessor());

        VocabCache<VocabWord> cache = new AbstractCache<>();
        WeightLookupTable<VocabWord> table = new InMemoryLookupTable.Builder<VocabWord>()
                .vectorLength(64)
                .useAdaGrad(false)
                .cache(cache).build();

        Word2Vec vec = new Word2Vec.Builder()
                .minWordFrequency(1)
                .iterations(5)
                .epochs(1)
                .layerSize(64)
                .seed(42)
                .windowSize(5)
                .iterate(iter)
                .tokenizerFactory(t)
                .lookupTable(table)
                .vocabCache(cache)
                .build();

        vec.fit();

        //Saves the model for use in other programs
        WordVectorSerializer.writeWord2VecModel(vec, "./Models/WordToVecModel.txt");


text:
How would one develop an action space for a game that is proprietary?
I'm currently trying to develop an RL that will teach itself to play the popular fighting game "Tekken 7". I initially had the idea of teaching it to play generally- against actual opponents with various levels of difficulty- but the idea proved to be rather complex. I've liquefied the goal down to "get a non-active standing opponent to 0 health as fast as possible".
I have some experience with premade OpenAI environments, and tried making my own environment for this specific purpouse, but this proved to be rather difficult as there was no user friendly documentation.
Below is a DQN that was coded along with the help of a YouTube tutorial
import numpy as np
from tensorflow.keras.layers import Dense, Activation
from tensorflow.keras.models import Sequential
from tensorflow.keras.optimizers import Adam

class ReplayBuffer(object):
    def __init__(self, max_size, input_shape, n_actions, discrete=False):
        self.mem_size = max_size#memory size dictated
        self.discrete = discrete#determines a number of discrete values that can be inputted
        self.state_memory = np.zeros((self.memsize, input_shape))
        self.new_state_memory = np.zeros((self.mem_size, input_shape))
        dtype = np.int8 if self.discrete else np.float32
        self.action_memory = np.zeros((self.mem_size, n_actions))
        self.reward_memory = np.zeros(self.mem_size)
        self.terminal_memory = np.zeros(self.mem_size, dtype = np.float32)

    def store_transition(self, state, action, reward, state, done):
        index = self.mem_cntr % self.mem_size
        self.state_memory[index] = state
        self.new_state_memory[index] = state_
        self.reward_memory[index] = reward
        self.terminal_memory[index] = 1 - int(done)
        if self.discrete:
            actions = np.zeros(self.action_memory.shape[1])
            self.action_memory[index] = actions
        else:
            self.action_memory[index] = action
        self.mem_cntr += 1

    def sample_buffer(self, batch_size):
        max_mem = min(self.mem_cntr, self.mem_size)
        batch = np.random.choice(max_mem, batch_size)

        states = self,state_memory[batch]
        states_ = self.new_state_memory[batch]
        rewards = self.reward_memory[batch]
        actions = self.action_memory[batch]
        terminal = self.terminal_memory[batch]

        return states, actions, rewards, states_, terminal

    def build_dqn(lr, n_actions, input_dims, fcl_dims, fc2_dims):
        model = Sequential([
                    Dense (fcl_dims, input_shape = (input_dims, )),
                    Activation('relu')
                    Dense(fc2_dims),
                    Activation('relu')
                    Dense(n_actions)])

        model.comile(optimizer = Adam(lr = lr), loss = 'mse')

        return model

    class Agent(object):
        def __init__(self, alpha, gamma, n_actions, epsilon, batch_size,
                     input_dims, epsilon_dec=0.996, epsilon_end=0.01,
                     mem_size = 1000000, fname = 'dqn_model.h5'):
            self.action_space = [i for i in range(n_actions)]
            self.n_actions = n_actions
            self.gamma = gamma
            self.epsilon = epsilon
            self.epsilon_dec = epsilon_dec
            self.epsilon_min = eps_end
            self.batch_size = batch_size
            self.model_file = fname

            self.memory = ReplayBuffer(mem_size, input_dims, n_actions,
                                       discrete = True)
            self.q_eval = build_dqn(alpha, n_actions, input_dims, 256, 256)

        def remember(self, state, action, reward, new_state, done):
            self.memory.store_transition(state, action, reward, new_state, done)

        def choose_action(self, state):
            state = state[np.newaxis, :]
            rand = np.random.radnom()
            if rand < self.epsilon:
                action = np.random.choice(self.action_space)
            else:
                actions = slef.q.eval.predict(state)
                action = np.argmax(actions)

            return action

        def learn(self):#temporal difference learning, delta between steps \
            #and learns from this
            #
            #using numpy.zero approach, only drawback \
            #is that batch size of memory must be full before learning
            if self.memory.mem_cntr < self.batch_size:
                return
            state, action, reward, new_state, done = \
                                    self.memory.sample_buffer(self.batch_size)

            action_values = np.arary(self.action_space, dtype = np.int8)
            action_indices = np.dot(action, action_values)

            q_eval = self.q_eval.predict(state)
            q_next = self.q_eval.predict(new_state)

            q_target = q.eval.copy()

            batch_index = np.arrange(self.batch_size, dtype = np.int32)

            q_target[batch_index, action_indices] = reward + \
                                    self.gamma*np.max(q_next, axis=1)*done

            _ = self.q_eval.fit(state, q_target, verbose=0)

            self.epsilon = self.epsilon*epsilon_dec if self.epsilon > \
                           self.epsilon_min else self.epsilon_min

            def save_model(self):
                self.q_eval.save(self.model.file)

            def load_model(self):
                self.q_eval = load.model(self.model_file)


text:
How do you interpret this learning curve?
Loss is MSE; orange is validation loss, blue training loss. The task is NN regression (18 inputs, 2 outputs), one layer 300 hidden units.

Tuning the lr, mom, l2 regularization parameters this is the best validation loss I can obtain. Can be considered overfitting? Is 1 a bad vl loss value for a regression task?

The validation loss settles exactly at an error of one. Probably means there's something off with either the kind of data validation set has or with something in the training. An exact validation loss of one almost definitely means there's something off.
I'd recommend before doing anything thoroughly go through your data or see if there's anything to debug in the model itself. Considering training error reduces there's probably something different about either the formatting of the validation data or the validation data itself.
A mild description of the type of data and exact problem in hand could further help.

What is 'almost definitely' wrong with an MSE of 1, and why?

Why would validation error trends settle at exactly one when it can take any real value. The only way validation error would settle is if the training defined a minima too hard for it to come out of exactly at a validation error of 1, meaning there's surely something to debug in the data.

You seem to overinterpret a coarse plot which, if zoomed in, would most probably reveal fluctuations around 1.0. It would be safer to ask for a clarification here than assuming that it is exactly 1.0. The plot by itself shows nothing wrong

Depends on what does 1 represent in your task.
If you are trying to predict household prices and 1 represents \$1, I think the average validation loss is good. If 1 represents \$10000 in this case, probably something is not right. But remember that there are 2 parts contributing to the overall loss. The mse loss and the l2 penalty loss. (Also remember that most optimizers already implement l2 penalty as weight decay. So you do not need to add it separately)
Some suggestions.

Check if your data has any outliers/ anomalies. Based on your task you should know as to what you can do with these data points. Also see if your dataset has high variance.
If you are worried about over-fitting, think about your data again. Less data + more parameters often leads to over-fitting. If your dataset is too small, you need to think again.
Try to adjust the number of hidden units and observe the results.
Try using cross validation.
Alternatively, try using different optimizers and see what happens (Try Adam).

The telltale signature of overfitting is when your validation loss starts increasing, while your training loss continues decreasing, i.e.:

(Image adapted from Wikipedia entry on overfitting)
It is clear that this does not happen in your diagram, hence your model does not overfit.
A difference between a training and a validation score by itself does not signify overfitting. This is just the generalization gap, i.e. the expected gap in the performance between the training and validation sets; quoting from a recent blog post by Google AI:

An important concept for understanding generalization is the generalization gap, i.e., the difference between a model’s performance on training data and its performance on unseen data drawn from the same distribution.

An MSE of 1.0 (or any other specific value, for that matter) by itself cannot be considered "good" or "bad"; everything depends on the context, i.e. of the particular problem and the actual magnitude of your dependent variable: if you are trying to predict something that is in the order of some thousands (or even hundreds), an MSE of 1.0 does not sound bad; it's not the same if your dependent variable takes values, say, in [0, 1] or similar.

The output is two values in floating point between -30 and 30: what can you say about MSE 1.0?


text:
Can Grad CAM feature maps be used for Training?
I am trying to recreate the architecture of the following paper: https://arxiv.org/pdf/1807.03058.pdf
Can someone help me in explaining how are the feature maps coming out of the output of GradCam used in the following conv layers?


text:
How did MuZero learn the rules of chess?
Google says that their new AI program MuZero learnt the rules of chess and some other board games without being told so. How is this even possible?
https://towardsdatascience.com/deepmind-unveils-muzero-a-new-agent-that-mastered-chess-shogi-atari-and-go-without-knowing-the-d755dc80ff08

Check Appendix A of the original paper, section titled "Actions Available". The rules are actually used at the root of the search tree. But after that, the hidden state is evaluated independent of the rules; the model learns to make legal moves. https://arxiv.org/pdf/1911.08265.pdf

Why do you think this is impossible? You could ask the exact same question about any feat of human learning. If you are interested in the specific algorithms that are used, you should clarify in your question.


text:
Does the substituted variable/constant have to appear in the unified term?
I'm checking out how to manually apply resolution on a first order predicate logic knowledge base and I'm confused about what is allowed or not in the algorithm.
Let's say that we have the following two clauses (where $A$ and $B$ are constants):
$\neg P(A, B) \vee H(A)$
$\neg L(x_1) \vee P(x_1, y_1)$
If I try to unify these two clauses by making the substitutions $\{x_1/A, y_1/B\}$ do I get $\neg L(A) \vee H(A)$ ? Is it allowed to substitute $y_1$ by $B$ even if $B$ doesn't appear in the unified clause?
Then we have the other way around where:
$\neg P(A, y_1) \vee H(A)$
$\neg L(x_1) \vee P(x_1, B)$
Can I do $\{x_1/A, B/y_1\}$ for $\neg L(A) \vee H(A)$ ?
What about the case where:
$\neg P(A, z_1) \vee H(A)$
$\neg L(x_1) \vee P(x_1, y_1)$
Can I substitute $\{x_1/A, y_1/z_1\}$ and get $\neg L(A) \vee H(A)$ ?
Finally there is also the cases where we have something like this:
$\neg P(x_2, y_2) \vee H(z_1)$
$\neg L(x_1) \vee P(x_1, y_1)$
Can we do $\{x_1/x_2, y_1/y_2\}$ to get $\neg L(x_3) \vee H(z_2)$ ?
I'm really confused about when unification succeeds once we have two clauses with a literal of the same kind (negation in one of them and not in the other one) that are a candidates for unification.

Hey I am currently studying First Order Logic right now and I think I can answer your question. Others please correct me if I am wrong.
For the first case, you can generally substitute variables with constants. Hence, you can make the substitution $\theta \leftarrow \{x_1 \leftarrow A, y_1 \leftarrow B \}$. This is used very commonly when you want to infer some query $\alpha$ from your knowledge base. $\alpha$ usually is in the form $P(A,B)$ as you have mentioned. When you unify you get $\neg L(A) \vee H(A)$ and ur substitution has to stay the same throughout the resolution algorithm. I.e, you cannot substitute $x_1$ for another constant / variable.
Regarding the second case, you cannot substitute a constant with a variable $B$ to another variable.
In general, you can substitute a variable with a constant, or another variable. You can also substitute a variable with a skolem function, Eg. $x_1 \leftarrow G(y)$. However, for skolem functions, you cannot substitute $x \leftarrow F(x)$, in which the variable names are the same.
Hope this helps !


text:
How to reduce variance of the model loss during training?
I know that stochastic gradient descent always gives different results. What are the best practices to reduce this variance today?
I tried to predict simple function with two different approaches and every time I train them I see very different results.
Input data:
def plot(model_out):
  fig, ax = plt.subplots()
  ax.grid(True, which='both')
  ax.axhline(y=0, color='k', linewidth=1)
  ax.axvline(x=0, color='k', linewidth=1)

  ax.plot(x_line, y_line, c='g', linewidth=1)
  ax.scatter(inputs, targets, c='b', s=8)
  ax.scatter(inputs, model_out, c='r', s=8)

a = 5.0; b = 3.0; x_left, x_right = -16., 16.
NUM_EXAMPLES = 200
noise   = tf.random.normal((NUM_EXAMPLES,1))

inputs  = tf.random.uniform((NUM_EXAMPLES,1), x_left, x_right)
targets = a * tf.sin(inputs) + b + noise
x_line  = tf.linspace(x_left, x_right, 500)
y_line  = a * tf.sin(x_line) + b

Keras training:
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(50, activation='relu', input_shape=(1,)))
model.add(tf.keras.layers.Dense(50, activation='relu'))
model.add(tf.keras.layers.Dense(1))

model.compile(loss='mse', optimizer=tf.keras.optimizers.Adam(0.01))
model.fit(inputs, targets, batch_size=200, epochs=2000, verbose=0)

print(model.evaluate(inputs, targets, verbose=0))
plot(model.predict(inputs))

Manual training:
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(50, activation='relu', input_shape=(1,)))
model.add(tf.keras.layers.Dense(50, activation='relu'))
model.add(tf.keras.layers.Dense(1))

optimizer = tf.keras.optimizers.Adam(0.01)

@tf.function
def train_step(inpt, targ):
  with tf.GradientTape() as g:
    model_out = model(inpt)
    model_loss = tf.reduce_mean(tf.square(tf.math.subtract(targ, model_out)))

  gradients = g.gradient(model_loss, model.trainable_variables)
  optimizer.apply_gradients(zip(gradients, model.trainable_variables))
  return model_loss

train_ds = tf.data.Dataset.from_tensor_slices((inputs, targets))
train_ds = train_ds.repeat(2000).batch(200)

def train(train_ds):
  for inpt, targ in train_ds:
    model_loss = train_step(inpt, targ)
  tf.print(model_loss)

train(train_ds)
plot(tf.squeeze(model(inputs)))

There are a few things you can play with:

Try reducing the learning rate, or increasing decay.
Try using regularization(L1/L2 or dropout)
Try using momentum(your model may be stuck in a local minima)
Adjust other hyperparams(nodes, layers, batch size, etc.)

Unless you have some knowledge about the specific cause of high loss variance, the above steps in some amount should get you where you need to go.

How to reduce variance with fixed hyperparameters? That was the question.


text:
The membership function of Consequents (Outputs) in Fuzzy classifier
The
problem in Iris data is to classify three species of iris (setosa, versicolor and virginica) by
four-dimensional attribute vectors consisting of

sepal length (x1)
sepal width (x2)
petal length (x3)
petal width (x4)

Every attribute of the fuzzy classifier is assigned with three linguistic
terms (fuzzy sets): short, medium and long. With normalized attribute values the
membership functions of these fuzzy sets for all the four attributes are depicted in the
figure below:

Now, consider the situation that a set of Rules are given - some examples are as below:

R1: If (x3=short OR medium) AND (x4=short) Then iris setosa
R2: If (x2=short OR medium) AND (x3=long) AND (x4=long) Then iris virginica

Now, I want to make a fuzzy classifier on Iris dataset. The problem here is, I need to use a membership function for Consequents in Rules(i.e, The 3 classes) so as to be able to compute aggregation of rules and difuzzification.

What is the proper pre-defined domain and membership function for three classes?
All the Consequents (Outputs)  in fuzzy classifier need to acquire membership functions?


text:
Which algorithm and architecture to use for 1:1 matrix transformation of an 8X8 dimension?
I would like to map the simplest 8X8 matrices, one to one, but am not sure which AI algorithm would give the best performance. I am thinking about the DeepLearning4j, however, I don't know which neural architecture to use.
I would like to make a simple and a very "stupid" bot for playing the chess. The result I am hoping to obtain is a system which can learn the chess rules rather than make intelligent moves (although it would be great if it could do that as well).  I understand that chess bots are nothing new, however, I am not interested in making a chess bot but a system that can simply learn by giving nothing else than an 8X8 matrix as an input and 8X8 matrix as an output. Chess is irrelevant, and it can be any other game that can be represented with values within an 8X8 matrix.
I am aware of the newest image mappers that transform horses to zebraz, but I need something more precise and 1 to 1 learning.
The amount of data I can get for learning is also not an issue (I can generate as much as I want).

There are Turing machine NNs and architectures that solve things such as the QR codes. TM NNs are not as evolved as they should be, while QR solving does not work for all cases (tested it on my own)... so there is currently no unique solution/architecture that would work for different game boards. Anyway, I came back to this problem after 5 years, and solved it on my own (kind of).


text:
What form of output would be needed to train a model on a connect 4 AI?
I've had a big interest in machine learning for a while, and I've followed along a few tutorials, but have never made my own project. After losing many games of connect 4 with my friends, I decided to try to make a replica of that, then create a neural network and AI to play against me (Or at least something where I can enter the current board scenario, and it will output which row is the best move). This may be an ambitious first project, but I'm willing to put in the work and research to create something I'm proud of. I created the game using p5.js, and though it may be simple, I'm really happy with how it turned out, as it's one of my first more interesting and unique projects in computer science. Now I don't know a ton about ML, so bear with me. I would like the use pytorch, but I'm open to tensorflow/keras as well.
Here are a few of my questions:

What output do I need to train? My game currently doesn't have a win condition. Would an array or matrix filled with a 0 where there isn't a chip, a 1 where a red chip is, and a 2 for a yellow? Ie

[0,0,0,0
 1,0,0,0
 1,0,0,0
 1,0,2,0
 1,2,2,2]

and enter a 1 somewhere to signify this as a win for player 1? Could an AI recognize this 4 in a row pattern as what needs to be done to win?

What is the best way to simulate a lot of games to get my training data? I'm imagining using an RNG to drop chips randomly, export the data output to a file and then enter whether it was a win for p1, p2, or a tie?
Any other general words of wisdom or links to read?

Thanks so much for reading this and any help you can offer?

On your first question, numerically for an AI,the difference between a 1 and a 2 could be difficult for it to decipher. Instead, I would suggest using a CNN and adding 2 different channels to the input, one for player 1 and another for player 2, then set the values in these channels to be a 1 for a chip or a 0 otherwise. This will form a sort of image of the board where, if overlayed, you might get like a blue pixel for player 1 and a red pixel for player 2, and a CNN could perform quite well on that.

@Recessive I will definitely look into that. Out of curiosity, why is it better to do this as an image and then turn it into data rather than just feed it data like a matrix? Would I input whole games or one move at a time? Are you saying to do one image for player 1 chips and 1 image for player 2 chips, overlay them and keep the others empty? Sorry I'm new at this but I appreciate the help!

While CNN's are designed for images, they work exceptionally well on any 2 dimensional data, as you can imagine any matrix with 2 dimensions as a really concise image. In this case, the data is still being fed in as a matrix, just into a CNN as CNN's handle 2d data very well. The data isn't changed in any way, it's only being looked at from a different perspective. Also, no, feeding whole games would be redundant, so just the current board state will do for determining a move. As for you last question - sort of. Search up "Channels in CNN's" to get a better understanding of this.

@Recessive Ok so you're saying use images of the board 1 move at a time? I'm looking at CNNs and yes, they seem like the best thing to use. So if I understand correctly, normally with CNNs you have to assign each image an output, like with the fashion database you assign each one a class, what would the outputs/classes be for each move?

Very good question. This is where it gets tough. If you wanted to do it best, you would use a https://en.wikipedia.org/wiki/Monte_Carlo_tree_search (a sort of modified minimax). However this might prove difficult. For the sake of simplicity, I would recommend just representing all board positions as a big output vector (7x6, so 42 output nodes) with each representing the next move. Using softmax, only one will be chosen.

Of course, this poses the problem of how you are going to train it. If you wanted to do it simply, you could cheat and use an already existing AI to determine the next best move, and using supervised learning, tell your AI what moves it should be making. If you wanted to be more legitimate with the training however, reinforcement learning is your best bet. Unfortunately, I am not very experienced with reinforcement learning, so can't help out heaps there, but I know enough to know it would be applicable in this circumstance.


text:
Designing a reinforcement learning AI for a game of connect 4
I've made a connect 4 game in javascript, and I want to design an AI for it. I made a post the other day about what output would be needed, and I think I could use images of the board and a CNN. I did some research into Reinforcement learning, and I think that's what I need to do. I don't have much experience with ML in general, much less RL with Q-learning, but that is what I'd like to do.
Now, I don't really know how to start out with such a big project. I have a few questions first:

What do I do with my input? I'm thinking I give the AI 7 options for moves to make, one for each row of the board. How do I implement a way that it can "look" at the board? Can I just import an image of the current board state?
How do I make a reward table? How should I do the points system for the Q-learning? I'm thinking something like: If it drops a chip it gets a point, if it lines up 2 chips in a row it gets 5 points, if it gets 3 in a row it gets 30, and if it gets 4 in a row it gets 100. Would that be an effective way to do this? How do I implement this?
Is there a library I can use to do any of the work where I make an algorithm and board states and reward tables? Or do I have to hard code any of it?
I've done some research, are there any links or tutorials you think I should read or follow along with? Any other general advice or help for me?

I greatly appreciate anyone who answers one or all of these questions! Thank you so much!

You don't need reinforcement learning for this, or any kind of ML, but it would work and is a fun thing to study and apply in this kind of game environment. Could you clarify whether your question is about AI routines for connect 4 (and you don't really care whether it is ML or RL), or is it about using connect 4 as a case study for Reinforcement Learning? Or do you just want a connect 4 bot (I expect they already exist)?

@NeilSlater I want to use ML or RL as a case study. I'm really interested in making my own AIs or bots, and learning how to write neural networks and things like that. I don't want just the solution, I want to design it and make it the hard way. I just don't know how to start.

You're asking too many questions here. Please, ask only one question per post.

1) your input should be so that you describe your entire environment. This could be done by 8 (length)* 8 (height)* 3 (either empty space, opponent chip or your chip) = 192 input neurons. you can just import a image of the current boardstate (which is width pixels * height pixels input neurons), but this means you task the neural network with learning to read the image as wel as playing the game.
2) rewards for a game like this are (most of the time) 1 for a winning move and 0 for a losing move. if you do it your way it might have side effects like prioritizing lining 2 chips up instead of going for a winning move.
3) Tensorflow is most commenly used. (this is python and not javascript though)
4) I liked the book Reinforcement learning, an introduction and would recommand this to anyone.

authors: Дизайнер GEIZER


text:
Is it possible to use AI for detecting the volume of a cup
I was just wondering if it's possible to use Machine Learning to train a model from a dataset of images of cups with a given volume in the image and then use object detection to detect other cups and assume the volume of the cup,
Basically the end goal is to detect the volume of a cup using object detection with a phone's camera,
I would highly appreciate it if someone can point me to the right direction.

This could be possible, providing you have the right dataset to train it on.
The volume of a cup consist of width, height and depth. You can probably detect all three of those given the bounding box or the pixels of the cup. However detecting the dimensions of an object require a reference object, like a penny or your finger and you have to specify the exact dimension of that. If that method fits your problem which I assume not, this is a good resource to look through: Open CV measuring dimensions
However to do the task, you need a way to measure the volume without the reference object. To fo this you need a deep learning based approach. Depth detection using fully residual convolutional neural network maybe a good start for your project as you are doing something similar. You may use one of the pretrained model and apply transfer learning on it with the image of the cup and the surroundings, and get the output and feed it through another feed forward neural network to predict the volume.


text:
Do backgroundSubtractor functions in opencv only detect moving objects?
There are some backgroundsubtractor functions in opencv like backgroundsubtractormog2 , backgroundsubtractorGMG and ... . It seems that these functions only detect moving objects in a video.
But I understand from the concept of these functions, that they do some clustering in an image.
Do these functions only detect moving objects? Why? Or am I wrong?
Any help will be appreciated


text:
Are there OpenAI Gym continuing environments (other than inverted pendulum) and baselines?
I would like to use OpenAI Gym to solve a continuing environment, that is, a problem with a single, never-ending episode (please note I don't mean a continuous environment with continuous state and actions).
The only continuing environment I found in their repository was the classic inverted pendulum problem, and I found no baseline methods (algorithms) that don't require episodic environments.
So I have two questions:

are there any continuing environments other than the inverted pendulum one?
is there an OpenAI Gym baseline method that I can use to solve the inverted pendulum problem as well as other continuing environments?

I'm not sure why you need a continuing environment, but actually you can make most (if not all) OpenAI Gym environments continuing. When you perform a step, you receive information about the next state, the reward, a termination signal and a dictionary with additional information. Simply ignore the termination signal if you want the episodes to continue indefinitely. In some cases you will need to modify a variable of the environments called $\texttt {_max_episode_steps}$, which may force the simulation to stop or to restart.
About your second question, check a resource called Spinning Up, from OpenAI too. They explain several methods and their implementation.

For most OpenAI gym environments, your suggested modifications will unconstrain the episode lengths, but that is not the same as making them continuous. E.g. this won't make MountainCar or LunarLander continuous - they are still goal driven to a terminal state, and any successful agent will solve them in that way.

I don't understand your point. The inverted pendulum is also driven to a terminal state, but can be understood as a continuing problem. What is the difference? Nonetheless, if you do these modifications to MuJoCo environments, they certainly will be continuing environments with no terminal state.

Thanks! Spinning Up is cool, why on earth don't they point to it on the OpenAI Gym main pages?

I need a continuing environment because I am working on a problem with one, although now I realize that I can still train them using a time limit and the use them in the continuing scenario.

Regarding Neil Slater's point, I think he means using your trick on environments that have a natural termination may be tricky. For example, once the mountain car is on top or the lunar lander is crashed, what does even mean to continue the episode? I was asking about environments that are naturally continuing and that can keep going indefinitely without large quantitative changes like reaching the mountain top or landing.

@DiegoGomez Yes user118967 has stated the same concern, not this is not addressed in your answer. I.e. you cannot turn an episodic problem into a continuous one simply by allowing more time steps.


text:
What ML algorithms would you suggest in fraud detection?
There are a lot of ML algorithms suggested for fraud detection. Now, I have not been able to find a general overview for all of them. My goal is to create this overview. What algorithms would you suggest and why?


text:
Correlating two models to predict the output of one that corresponds to an output of the other
I am currently working on a problem and now got stuck to implement one of it's steps. This is a simple attempt to explain what I am currently facing, which is something that I am aiming to implement in my python simulation.
The idea is that I will some input parameters into my simulation, however one simulation is not able to perfectly capture all the dynamics involved in a real scenario. Hence, what I am aiming to do is to feed some inputs of the real scenario into my simulate and perform the simulation for all cases in which I have real data. So I will have the same amount of data for technically the same situation for both real and simulated scenario.
With my simulated data I can find out the optimal parameters(for the simulation), so the idea now is to correlate my simulated model with the real data, and then, with this correlation, find out what would be the equivalent of the optimal simulated parameters into the the optimal real parameters. Here not really precise diagram that might help on the visualization of the problem:

I have already seen a lot of machine learning being utilized to fit to a set of data, but haven't really seen anything that could help me on this task that I currently have in hand, as "fitting models". So here comes the questions, how to correlate the models and utilized it to extract the optimal parameters.
Hope that I managed to be succinct and precise albeit the length of the text. I would really appreciate your help on this one!


text:
Optimisation of dependence of efficiency of CNN on training data
I got a large dataset of images (dimensions of 16 x 16, 250k samples) and corresponding spherical coordinates (distributed uniformly in each coordinate). On these, I trained a convolutional regression network to directly yield the coordinates for a provided image. The network itself is rather simple and consists of multiple convolutional layers where the last of them is flattened and followed by some dense layers to get the desired output. Since the input image size is rather small, pooling layers are obsolete I think (doesn't make much difference if used).
If I now train on all of the data I will get reasonable results in the end. But, if I filter them before training, i.e. only use coordinates which are limited by a certain radius, the network will increase it's performance quite a bit, but will only work well if my input image corresponds to the parameter space used during training.
So my question is, if the network isn't deep enough or has the wrong architecture to perform on the complete dataset with high confidence or if this is expected behaviour. One naive approach would be to train the network for different coordinate ranges and to store the weights for each of them. Then, you could train a classifier to decide in which range you are and use the previously determined weights for the network accordingly. But this seems strange to me, as a single network should somehow be able to achieve the same without this weird architecture, I think.
I would be pleased if someone has an idea how I could optimise the performance of my network to yield the best results over the whole coordinate space.


text:
Applying Machine Learning to 2D Laser Scanner Data
We are using 2D Laser Scanner to scan various objects of different geometric shapes for e.g. cylinder, spiked, cylinder with notch, cylinder with curved edges e.t.c. The dataset contains points in the format [x, y] with the dimension of 1 complete scan being 160x2. The goal is to use these scan points to classify the various shapes.
I have used a multilayer NN with sigmoid as the final layer and Adadelta optimizer for this problem but the accuracy reaches only upto 70%.
Can anyone recommend a proper model that can be used for Laser Scanner Data Classification?

          MODEL
def baseline_model():
    model = Sequential()
    model.add(Dense(2048, input_dim=160, activation='relu'))
    model.add(Dropout(0.1))
    model.add(Dense(1024, activation='relu'))
    model.add(Dropout(0.1))
    model.add(Dense(512, activation='relu'))
    model.add(Dropout(0.2))
    model.add(Dense(256, activation='relu'))
    model.add(Dropout(0.3))
    model.add(Dense(128, activation='relu'))
    model.add(Dropout(0.4))
    model.add(Dense(64, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(32, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(6, activation='softmax'))
    Adam = optimizers.Adam(lr=0.001)
    Adadelta =  optimizers.Adadelta(lr = 1)
    model.compile(loss='categorical_crossentropy', optimizer=Adadelta,   metrics=['accuracy'])

You could convert this problem to shape detection on an image, where you can probably use few-layer convolution networks to solve the problem. You would introduce a lot of new variables but it would be easier to solve it that way.

According to this paper https://www.researchgate.net/publication/321816644_Deep_learning_for_2D_scan_matching_and_loop_closure the 2x scan goes through the following layers

Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Am confused - the researchgate link is the citation


text:
Need examples for the following definitions
I am currently reading the paper "Similarity of Narratives" by Loizos Michael (link below) and I am having a hard time figuring out the definitions listed (p.107 - p.109).
Could someone please give me a practical example for each of the definitions?
Article: http://narrative.csail.mit.edu/cmn12/proceedings.pdf

Welcome to SE:AI! It would be helpful to excerpt the specific text your are asking about, to make the question more widely useful and improve your chances of getting answers. (In this case, specifically listed the terms you are seeking clarification on.) I'm leaving this question open, but you should be aware that it has received multiple close-votes for the reasons I've outlined.

The 'vocabulary' used is:

$\mathscr{F}$ - fluents, conditions that change over time. The predicate holds(<fluent>,<state>) defines whether a condition applies in a given state.
$\mathscr{A}$ - actions, describe, erm, actions that happen. The predicate occurs(<action>,<state>) specifies that a given action happens at a particular state (presumably triggering a change to a new state, and changing the value of one or more fluents)
$\mathscr{T}$ - time points, which specify a chronological ordering.

Now we can look at the actual definitions: a discourse combines events (actions) and facts (fluents) and provides a (partial) ordering, ie a sequence in which they occur. This is represented in an acyclic graph. So the discourse describes a sequence of events that happen in a particular order and have an effect on facts. The ordering is relative, as there are no absolute time reference points give. Actions and facts are expressed in predicate calculus by the predicates mentioned above. Actions can involve a character moving from location A to location B; the fluent describing the location of the character will have been changed through that action.
An embedding assigns a given point in time to each state in the discourse. Each state is assigned a time point in a way that is consistent with the relative timings of the states in the discourse. So you have a general story, and you fix each action in time. The absolute time of an action in the embedding has to be before/after other actions according to their order in the discourse.
A domain adds two further predicates to a discourse, namely static($\phi$) and causes($\phi$,<fluent>). These formulas $\phi$ express logical constraints, that add consistency to the discourse. For example, if an action involves killing a character, the consequence has to be that the character is dead afterwards. So that action mandates a particular change, which would be encoded by such a formula. If the character was then to do some action after having been killed, that would invalidate the discourse in that domain. Different domains might have different constraints etc.
A model then works out if the domain is consistent, by evaluating all the actions and events using the domain constraints, and assigning it a truth value depending on whether it is possible or not. I might be wrong there, as I'm not sure I have interpreted the definition correctly — please let me know in a comment if that is the case.
Basically, if a model for a domain exists, it means that the actions and facts are consistent, and hence the narrative works (it is "a discourse compatible with a given domain"): a narrative is a discourse in a domain which, when embedded in a timeline, is consistent.
A default domain is one domain out of a set of other domains which seems preferable over the others.
(I have to stop here for lack of time — I might be able to expand this answer later)


text:
Sequence-to-Sequence models without specifying the start and end of sentences
Is there a seq-to-seq model which does not require to know the start and end of a sentence? I need to model a system which gets a long sequence of words and creates a long sequence of tokens as long as the input. For example it takes a sequence of 1000 words and creates a sequence of 1000 tokens, each token corresponds to an input word.

What do you mean? You mean a system that tokenize a sentence? A system taht does that do that does not need teh start of the sequence and anchor not does it uses a neural network based approach.

So, isn't there any model that creates a seq-to-seq model without tokenizing?


text:
What is the most accurate pretrained sentiment analysis model by 2019?
I've been using OpenAI's 2017 Sentiment Neuron implementation (https://github.com/openai/generating-reviews-discovering-sentiment) for a while, because it was easy to set up and was the most accurate on benchmarks. What is the most accurate alternative now that I should use?

For best results, I'd recommend Google Cloud Machine Learning. It has [Natural Language Processing API] (https://cloud.google.com/natural-language/docs/basics) with Sentiment, Entity, and Entity-Sentiment analysis.
You can implement in C++, PHP, Python, or other languages. This does require running a virtual machine instance on Google Cloud. TensorFlow can also be used for NLP sentiment analysis. The only drawback is it's not economical.
As an alternative, this is something I came across recently by Fast Text : http://fasttext.cc.
They have some pre-trained models trained on yelp and some other datasets. They support a lot of languages


text:
Should an RL agent directly observe the reward?
I am training an A2C reinforcement learning agent in a dense reward environment (where rewards are known and explicit at every timestep).
Is it redundant to include the previous reward in the current observation space?
The reward is implicitly observed by the agent when collecting experiences and updating the network parameters. But could it also be useful for the agent to explicitly observe the reward of its previous action?

By "current observation space" do you mean "current state"? In your environment, what is the relationship between observation and state?

@NeilSlater yes, current observation and current state are the same thing. I use the terms interchangeably


text:
Need to analyze input CSV files and determine whether input file is good or bad w.r.t it's data
We have a scenario where we need to implement an Artificial Intelligence solution which will evaluate the input data file of my Azure Data Factory pipeline and let us know whether the file is good or bad with respect to it's data.
For example, I have 10 files several rows which are good input files and 2 files with several rows which are bad input files.
Each file either it is good/bad has 26 columns. The above two files are bad because of below reasons.

One file has all empty values for one column which is not expected.
Another file has, the value 'TRUE for all rows for a specific column which was also not he general scenario. (some % of TRUE's and some % records with FALSE will appear in good files)

Like this, there may be several scenarios where the input file may be treated as bad file.
We want to implement an Artificial Intelligence solution which should analyze all the input files and identify the hidden patterns of the data in file and detect abnormal scenarios like above and should eventually mark the file as bad file.
Please suggest for the approach or what components in Azure can help to achieve this kind of file sanity check.
Thanks.

This does sound a little bit like over-engineering. You might get a better result following predefined heuristics than implementing some form of machine learning.  That begin said, if you are set on using an AI, you could try using a feedfoward network (as this doesn't sound like a difficult task) and using % of TRUE's per column as an input, or other various values, with 2 output nodes of good or bad.

Thanks Recessive. Even i thought of doing with the help of file statistics like, type of column, how many rows has values, how many distinct values for each column, how many rows for each categorical ..etc. But, unfortunately, that was not accepted.BTW, I am new to machine learning/ AI. Could you please more details on your possible solution so  that I can search and understand it more.

You mightn't even need to use tensorflow or large libraries, try this: https://towardsdatascience.com/lets-code-a-neural-network-in-plain-numpy-ae7e74410795. If you do want to use a dedicated framework, here's a simple tutorial: https://machinelearningmastery.com/tutorial-first-neural-network-python-keras/

Thank you very much Recessive. I will go-through them. Thanks for your immediate help.


text:
Does a varying ANN model accuracy mean underfitting or overfitting?
Background:
This is for a simulated robot with four legs, walking on a flat terrain. The ANN (an MLP) is given inputs as the robot's body angle, positions and angle of each leg with respect to the body and two points of contact with the terrain, on each leg (if there's no contact, the value is zero). The outputs are the four motor rates for each leg.
I'm using Keras with the CNTK backend to train the network. The network has 30 input nodes (ReLU), one hidden layer with 64 nodes (ReLU) and an output layer with 4 nodes (Sigmoid). Optimizer is Adam.
The training data has 2459 datapoints. Running model.validate with parameters testDataPercentage = 0.25, epochs = 50 and batchSize = 10 gave me:   loss: 2.9509 - accuracy: 0.3283 - val_loss: 2.8592 - val_accuracy: 0.3213.
But running model.evaluate multiple times gave me:
['loss', 'accuracy'] [3.10, 0.50]
['loss', 'accuracy'] [3.04, 0.23]
['loss', 'accuracy'] [3.01, 0.11]
['loss', 'accuracy'] [3.45, 0.02]
['loss', 'accuracy'] [3.17, 0.40]
['loss', 'accuracy'] [3.03, 0.27]
['loss', 'accuracy'] [3.012, 0.46]

Loss doesn't decrease much over 50 epochs. It reduces from maybe 3 to 2.8. That's it.
Question:
I don't understand why the accuracy varies so much for each run.
If I add a hidden layer or even add a dropout of 0.2, the results are similar: loss: 2.9253 - accuracy: 0.2978 - val_loss: 2.9350 - val_accuracy: 0.3148.
Reducing the number of hidden nodes to 15 gives the same results: loss: 2.9253 - accuracy: 0.2978 - val_loss: 2.9350 - val_accuracy: 0.3148. Hidden layers with 64 nodes gives the same results. Training data with just 500 data points also gives the same results. Using sigmoid instead of ReLU gives slightly worse results.
I've been through many tutorials and guides on how to debug or check why the neural network is not working, but they don't teach properly, what these values mean and how to adjust the network.
Does the loss not decreasing, mean the network is not learning?
Does the fact that increasing or decreasing the layers or the number of training data mean that the network is not learning?

The inputs are quite complicated for an MLP, you might find better results if you reduce the number of inputs being fed in. As for loss not decreasing, yes that generally means the network has stopped learning. Quite often a neural network will not learn a problem not matter how many neurons or layers you throw at it, and then it's likely an issue of using a better suited model. This uses pytorch, but you might find some help here: https://github.com/juanto121/qwop-ai

Thank you, but reducing it down to the most important 9 input parameters also didn't help. The losses are still an almost flat horizontal line and the accuracy fell loss: 2.9470 - accuracy: 0.3576 - val_loss: 2.9396 - val_accuracy: 0.2443. For these types of inputs and outputs I don't see how an RNN or LSTM or CNN would help. MLP is the only one possible.

There is a chance that there is an error in your structure, just verify first that the network is able to learn a known value - say how to count up in binary (ie, input of 010 results in 011). How are you training this network? What are you using as training data?


text:
Deciding std. deviation for policy network output?
When I try to fit a Normal Distribution to the output of a policy network, for a continuous action space problem, what should be its standard deviation? mean for the distribution will directly be the output of the policy network.


text:
Regression using neural network
I'd like to ask for any kind of assistance regarding the following problem:
I was given the following training data: 100 numbers, each one is a parameter, they together define a number X(also given).This is one instance,I have 20 000 instances for training.Next, I have 5000 lines given, each containing the 100 numbers as parameters.My task is to predict the number X for these 5000 instances.
I am stuck because I only know of the sigmoid activation function so far, and I assume it's not suitable for cases like this where the output values aren't either 0 or 1.
So my question is this : What's a good choice for an activation function and how does one go about implementing a neural network for a problem such as this?

Lets mock some data up.

"100 numbers, each one is a parameter, they together define a number X(also given)"

# i.e. size of X_train -> [n x d]
# i.e. size of X_train -> [??? x 100]  , when d = 100

# "I have 20000 instances for training"
# i.e. size of X_train -> [20000 x 100], when n = 20000

import torch
import numpy as np

X_train = torch.rand((20000, 100))
X_train = np.random.rand(20000, 100) # Or using numpy

But what is your Y?
# Since the definition of a regression task,
# loosely means to predict an output real number
# given an input of d dimension

# So the appropriate Y_train would
# be of dimension [n x 1]
# and look like this:

y_train = torch.rand((20000, 1))

y_train = np.random.rand(20000, 1) # Or using numpy

What is a linear perceptron?
Taking definition from this tutorial

Thus, in picture:

Next we need to define training routine,
For now take it as biblical truth that this is an okay routine to train a neural net model (this isn't the only way but easiest or supervised learning):

In code:
import math
import numpy as np
np.random.seed(0)

def sigmoid(x): # Returns values that sums to one.
    return 1 / (1 + np.exp(-x))

def sigmoid_derivative(sx):
    # See https://math.stackexchange.com/a/1225116
    # Hint: let sx = sigmoid(x)
    return sx * (1 - sx)

def cost(predicted, truth):
    return np.abs(truth - predicted)

num_epochs = 10000 # No. of times to iterate.
learning_rate = 0.03 # How large a step to take per iteration.

# Lets standardize and call our inputs X and outputs Y
X = np.array(torch.rand((20000, 100)))
Y = or_output

for _ in range(num_epochs):
    layer0 = X

    # Step 2a: Multiply the weights vector with the inputs, sum the products, i.e. s
    # Step 2b: Put the sum through the sigmoid, i.e. f()
    # Inside the perceptron, Step 2.
    layer1 = sigmoid(np.dot(X, W))

    # Back propagation.
    # Step 3a: Compute the errors, i.e. difference between expected output and predictions
    # How much did we miss?
    layer1_error = cost(layer1, Y)

    # Step 3b: Multiply the error with the derivatives to get the delta
    # multiply how much we missed by the slope of the sigmoid at the values in layer1
    layer1_delta = layer1_error * sigmoid_derivative(layer1)

    # Step 3c: Multiply the delta vector with the inputs, sum the product (use np.dot)
    # Step 4: Multiply the learning rate with the output of Step 3c.
    W +=  learning_rate * np.dot(layer0.T, layer1_delta)

Now that we learn the model, i.e. the W.
When we see the data points that we need to use the model on, we apply the same forward propagation step, i.e. layer1 = sigmoid(np.dot(X, W))
Since we have:

I have 5000 lines given, each containing the 100 numbers as parameters.My task is to predict the number X for these 5000 instances.

And in code:
# If we mock up the data,
# it should be the same internal dimension.
X_test = np.random.rand(5000, 100)

# The desired output just needs to pass through the W and the activation:
# the shape of `output` -> [5000 x 1] ,
# where there's 1 output value for each input.
output = sigmoid(np.dot(X_test, W))

There's some weird things happening here when we design our network with a sigmoid, we naturally force the output values to be between the (0, 1) range. But this is partly because when we mock up the data using np.random.rand, the values are expected to fall between the (0,1).

A normal regression task where the output has arbitrary range of values, simply skip the sigmoid layer for the forward propagation and then the error derivatives in the sigmoid_derivative(layer1) would just be 1.

The quick answer is that you want to use an activation function on the output layer that does not compress values to $(0,1)$. Depending on your software, this might be called "linear" or "identity". It looks like Keras just wants you to leave off the activation function: model.add(Dense(1)).
The typical way of thinking of a neural network as a classifier (let's say a binary classifier) is just extending a logistic regression. In fact, when you use a sigmoid activation function on the output node, you're (sort of) running logistic regression on the final hidden layer.
A logistic regression is one type of generalized linear model. The gist of GLM is that some transformation of the the value of interest is a linear function of the feature space.
Let $X$ be the data matrix for the feature space. Let $\beta$ be a parameter vector. Then $\hat{y} = \mathbb{E}[y] = X\beta$ is the linear model, and $g(\mathbb{E}[y]) = X\beta$ is the generalized linear model (vectorized, so apply $g$ to each $y_i$).
But we could extend this to a nonlinear transformation, and when a neural network is a binary classifier, this is precisely what we're doing. Instead of the transformation of $X$ being given by $\beta$ and thus linear, we apply some nonlinear transformation $f$ and get $g(\mathbb{E}[y]) = f(X)$.
The terminology in GLM is "link function", but that is essentially the activation function on the final node(s) of the neural network. Consequently, all of the GLM link functions are in play, and one of those link functions is the identity function. For a GLM, that's just linear regression. For your neural network, it will be a neural network (nonlinear) regression, which sounds like what you want.

Usually you're normalizing the data first, meaning that your whole dataset will be in between 0 and 1. Afterwords after you're having the model predictions, when computing the cost function or evaluating the model, you can apply the inverse of the normalization function.

I'm a little confused now, the point of the sigmoid function is to put the data set between 0 and 1?

No, you use sigmoid to introduce non-linearity in your model. In addition sigmoid is especially used for models where we have to predict the probability as an output since it's defined in the range of 0 and 1. For normalizing the data i would suggest you to look at min-max normalization or z-score normalization.

for regression, you can use a hidden layer with sigmoid, then a LINEAR output layer, where the weighted sum goes straight through, without modification.
this way your output is not restricted to 0-1

Alternatively, you may use ReLu activation funtion. ReLu stands for Rectified Linear units and is defined as : max(x, 0)
So , when dealing with problem where the output is not restricted just to 0-1, you may want to use "ReLu" activation function for all the hidden layers and "linear" activation function for the output layer.


text:
Relationship between model complexity (depth) and dataset size
I'm new to deep learning. I was wondering what's the relationship between a deep model complexity (e.g. total number of parameters, or depth) and the dataset size?
Assuming I want to do a binary classification with 10K data for a problem like fire detection. How should I know what complexity I should go for?

In general, this is may not be an easy question to answer. The branch of artificial intelligence that studies these issues is called computational (and statistical) learning theory. See also https://cs.stackexchange.com/q/75327/20691. I will eventually try to answer this question, but I don't know when.

Thanks. Yeah try to write something so i can give u some credit.

A recent question (https://ai.stackexchange.com/questions/39176/why-are-neural-networks-so-data-hungry) seems related to this one.


text:
How are data assimilation and machine learning different?
This might seem like a really silly question, however I have not been able to find any answers to it on the internet.
From my rough understanding of data assimilation, it combines data with numerical models by having weights on the adjustment initial condition parameters? That sounds really similar to what machine learning/neural network does.
What are the distinct differences?


text:
Can a character-level Seq2Seq setup learn to perfectly reconstruct structured data like name strings?
If not perfect, how well can they do? For example, if I give the Seq2Seq setup a name it did not see in the training process, can it output the same name without error?
Example
name = "Will Smith"
output = DecoderRNN(EncoderRNN(name))
can_this_be_true = name == output

If you give it a name, it will probably be almost perfect model, as the number of hidden units are definitely enough to store the raw data of a name. However as a neural network it will still not be perfect. There may also be serious overfitting if you do this. A Seq2Seq model have way more parameters than necessary to just "remembers" all the possible names, as names variants are not a lot.