You are on page 1of 7

Computational intelligence notes

03-04
First lecture.
Introduction time.
Use canvas messages.
NU 5b-21, wednesday 15:30 (dan lange woensdag maar niet donderdag)
5 assignmenets for algorithms → apply methods for questions as well, not just programming. Write
short report.
Deadlines on tuesday?
many disciplines own definition intelligence.
Theory of mind, communication, use of tools are examples of intelligence. Swarm intelligence →
group works together. Can also be innate or acquired behaviour that allow an agent to solve problems
and achieve its goals.
Computations → the action of mathematical calculation, the use of computers.
Knowledge → experience/data represented by facts and information.
AI and CI have a lot of overlap, see slide 19
AGI → artificial generla intelligence that knows a broad rang eof tasks (human level problem
solving), multiple realizability.
Symbolic AI (rule based/expert systems);

05-04
Optimization; lecture 2
Searching all parameters to find best solltuion for current problem.
curve fitting → regression back in the house.
(sum squared error optimisation).
knapsack → fit as muoch items in the bag as possible.
FInd min or max for f(x)x ar ethe optimization variables,
f is the bjectiv efunction, c is the constraint functiona dn x is the search space. Local minima
exist sometimes, but we want to find the global minimum.
domain can be both discrete and continuous. fx* ,=f(x). can be local because of certain
constraints.
Continuous optimization gets benchmarked with hard functions.
Some work better for other (many local minima, bowl shaped, plate shaped, valley shaped,
steep ridges/drops). overfitting vs too much generalization.
Salesman can be done simply by force. (n-1)! possible roots possible here.
Representation can be complex.

Travelling salesman → graph with nodes and edges. → gg ez. Can also be nodes in a vector space
where a random point is the 0,0 point and every distance between a point can be represented by the
distance between the vectors.
Assignment 1
derivative with respect to x1:
2x+0.3*3pie sin(3piex)
derivative with respect to x2:
4x+1.6piesin(4piex)
to put together → each is for one of the axis → in python; numpy array, with 1 row and 2 columns.
(matrix). multiply by vertical column [f1,f2].

12-04
probabilistic learning and sampling methods.
model process of flipping a coin
observing c =1 → x(p(c=1)
1-x = tails outcome.
p(c given x ) = x^ c(1-x)^(1-c) bernoulli distribution. Dataset observation is independent as
events do not influenc each other.
Likelihood function; chance of getting the specific dataset. We want to minimize the negative
log-likelihood function (minimize loss). Logo easier as log of products is the sum of the logs,
as the lowest points will still be at the same location.
Derivative equal to 0 → x not moving anymore so that is the optimum.
Once you’ve found the derivative equal to 0, we can find the optimal x based on the given
dataset.
Determin p(y given x), determine p(D given x). → check constraints, find the best solution b
yminimizing log p(D given x).
Sampling methods.
Estimating pi; we know that the area is pir^2 and square area is 2r^2
9/40 out circle. 31/40 in circle. 31/40 x 4 = 124/40 = 3.1
Expected volume;
4*1/N Sum over I[x^2+Y^2<r^2].

break

Stanislaw ulam. .Monte carlo methods. Try to be solved by sampling as much combinations
of 52 cards as possible. Problem with sampling (curse of dimensionality). With each
dimensions, we have to do a multitude of checks. solved by markov chain monte carlo
approach. Making new samples dependent on the past, we use a proposal distribusition too
obtain a chain that corresponds to a sample form the original distribution.
Metropolis-hastings algorithm → initialize xt:= x0.
WE generate a sample, calculate the acceptance probability and then select until we find the
best one.. Check if the chance that the new solution divided by the old solution is greater
than 1 (better chance to be true). THe higher the difference, the bigger the chance it gets
replaced. THis chance makes it possible that worse solutions replace it sometimes, and
better ones are guaranteed to accept. Worse you might (and keep exploration that way). The
higher the chance, the gloser it is to the previous sample (guess). The size of sigma matters.
Small sigma will find limited graphs, high sigma will jump a lot but not accept a lot.
More exploration which leads to the global solution more often than hill-climbing.
With simulated annealing → slightly different acceptance probability formula. In the beginning, we
discover a lot more, then slowly reducing the speed we move around with, hopefully when we are
closer to the solution. We have more probability at the start to go somewhere that has a worse current
solution. T stands for temperature → starts high, goes lower and lower. Increased exploration, T
formula; T = (C ln(t+T0))^-1.
Assignment has two-dimension search space. WIth high temperature comes high
exploration, with low temperature comes high accuracy but low exploration.

assignment 2

class MetropolisHastings(object):
def __init__(self, x, prob, std=0.1):
self.prob = prob
self.std = std
self.x_old = x

def proposal(self, x):


# PLEASE FILL IN
# ...
# x_new = ...
x_new = np.random.normal(x, self.std, size=x.shape)
return x_new

def evaluate(sef, x_new, x_old):


# PLEASE FILL IN
# A = ...
A = self.prob(x_new) / self.prob(x_old)
return np.minimum(1.0, A)

def select(self, x_new, A):


# PLEASE FILL IN
# ...
# NOTE: If a new candidate is not selected, we must return self.x_old
u = np.random.uniform()
if u < A:
return x_new
else:
return self.x_old

def step(self):
# 1. Proposal
x_prop = self.proposal(self.x_old)
# 2. Evaluate
A = self.evaluate(x_prop, self.x_old)
# 3. Select
x_new = self.select(x_prop, A)
return x_new
slides lecture 4
improve performance by searching through multiple candidate solutions, or how to use
information about their quality to speed up optimization.
population based methods; key idea being that running an algorithm multiple times in
parallel, then exchanging info about the adjective among the solutions found.
1. initaliziation population of solutions and evaluate:
2. repeat until stop; generate solution, evaluate, select solution
generate through probability distributions or transformation of solutions in the already
existent population. We can select deterministic or stochastic.
generation can also be extended upon through mutation and recombination.
Genetic algorithm: assume maximatization and use the formula pi = f(xi)/sum of j f(xj)
we then do crossover and mutation in order to determine what we will be testing next.
N-queens problem; problem where we want to place queens such that none can attack
another; where we also see over generatins a rising fitness, slowly converging towards an
optimum. IN ass. 3, we slowly want to see the loss convergence lower over generations.
These evolutionary algorithms are continuous.

slides lecture 5
we continue on about genetic algorithms. Crossover starts with the first one and switches
after a random point. After all have been determined, 1 random mutation occurs. Evolve
Crossover and mutation are two different types, each having a slightly different effect. With
symbolic regressions, we kind of seem to add variables where we get closer and closer to
the desired graph results we are looking for.
With differential evolution, we;
1. randomly initilize np number of n-dimensional real vectors xi in Rn, and i in {1,..NP}
2. for each xi (target vector), find the f(xi) = fitness i
a. while satisfactory solution is not found
i. foreach xi in p
1. randomly select 3 distinct individuals xrr1, xr2, xr3 from the
population different than the target vector
2. generate a mutant vector vi = xr1 + F(xr2 - xr3)
3. generate a trial vector using binomial crossover u(i,j) = vij if
rand([0,1]))<CR or j= randi([1 ,D]); otherwise ;
4. if f(ui),=f(xi), xi ← ui
Applied in CMA-es
The estimation of these distribution algorithms fucking suck, but similar to in lecture 4.
Important to notice in the selection step that we set Pt+1 to St+1.
Fitness function → corresponds to objective function, could be modified to improve the searching
process. Linear dynamic scaling;
flds(x) = alpha f(x) - min{f(x’):x’in Pt}, where alpha>0 is a hyperparameter.
other common issues with the fitness function; dominance, crowding, vanishing selective
pressure.
Selection mechanisms are either parental selection or survivor selection. Parent selection is
used for recombination and mutation while survivor is used to determine the next population.
Random selection is parent selection, proportional selection is that as well, where we use
the fitness formula again, and assuming maximization again. The issue might be dominance;
premature convergence.
IN rank selection we can have linear ranking and exponential ranking
Implementing selection mechanisms can be done through roulette wheels, but also
tournament selection.
Survivor selection; notation with u and lambda, where u is the number of parents and
lambda the number of individuals in the offspring. Replacement is fitness-based.
Fitness based replacement;
- the worst individuals are replaced by offspring
- elitism; a subset of best individuals is kept together with the offspring
- tournament selection; select individual and compare with q individuals, then pick the
guy with most “wins”
Mutation functions such that f: X → X
Transformation depends on representation; binary, integers, combinatorial, continuous,
graphs.
Recombination can also be done, once again depending on the representation and the
method.

origineel class A;
class EA(object):
def __init__(self, repressilator, pop_size, bounds_min=None, bounds_max=None):
self.repressilator = repressilator
self.pop_size = pop_size
self.bounds_min = bounds_min
self.bounds_max = bounds_max
# -------
# PLEASE FILL IN
# all necessary hyperparameters come here
# -------

# -------
# PLEASE FILL IN
# all necessary operations (e.g., mutation, selection) must come here.
# -------

def parent_selection(self, x_old, f_old):


# do something

x_parents = x_old
f_parents = f_old

return x_parents, f_parents

def recombination(self, x_parents, f_parents):


# do something

return x_children

def mutation(self, x_children):


# do something

return x_children

def survivor_selection(self, x_old, x_children, f_old, f_children):


# do something
x = np.concatenate([x_old, x_children])
f = np.concatenate([f_old, f_children])

return x, f

# Evaluation step: DO NOT REMOVE!


def evaluate(self, x):
return self.repressilator.objective(x)

def step(self, x_old, f_old):


# -------
# PLEASE FILL IN
# NOTE: This function must return x, f
# where x - population
# f - fitness values of the population
# -------

x_parents, f_parents = self.parent_selection(x_old, f_old)

x_children = self.recombination(x_parents, f_parents)

x_children = self.mutation(x_children)

f_children = self.evaluate(x_children)

x, f = self.survivor_selection(x_old, x_children, f_old, f_children)

return x, f
computational intelligence practice exam
1C
2A
3D
4B
5A
6A
7A
8D
9C
10D
11A
12C
13B
14 C
15D
16A
17B
18D
19A
20D

1,2,3,4,5,7,8,10,11,13,14,16,17,18
14 goed
6,9,12,15,19,20
6 fout

juist:
1c
2a
3d
4b
5a
6c
7a
8d
9b
10 d
11 a
12 d
13 b
14 c
15 c
16 a
17 b
18 d
19 b
20 b

You might also like