MATLAB: Undefined operator ‘<' for input arguments of type 'timeseries'.

ga

I'm having trouble running a genetic algorithm,how to deal with an error like this? where the problem is in part
Undefined operator '<' for input arguments of type 'timeseries'.
Error in selection (line 5)
if any([population.Chromosomes(:).fitness] < 0 )
this is code :
function [parent1, parent2] = selection(population)
M = length(population.Chromosomes(:));
if any([population.Chromosomes(:).fitness] < 0 )
a = 1;
b = abs( min( [population.Chromosomes(:).fitness] ) );
Scaled_fitness = a * [population.Chromosomes(:).fitness] + b;
normalized_fitness = [Scaled_fitness] ./ sum([Scaled_fitness]);
else
normalized_fitness = [population.Chromosomes(:).fitness] ./ sum([population.Chromosomes(:).fitness]);
end
%normalized_fitness = [population.Chromosomes(:).fitness] ./ sum([population.Chromosomes(:).fitness]);
[sorted_fitness_values , sorted_idx] = sort(normalized_fitness , 'descend');
for i = 1 : length(population.Chromosomes)
temp_population.Chromosomes(i).Gene = population.Chromosomes(sorted_idx(i)).Gene;
temp_population.Chromosomes(i).fitness = population.Chromosomes(sorted_idx(i)).fitness;
temp_population.Chromosomes(i).normalized_fitness = normalized_fitness(sorted_idx(i));
end
cumsum = zeros(1,M);
for i = 1 : M
for j = i : M
cumsum(i) = cumsum(i) + temp_population.Chromosomes(j).normalized_fitness;
end
end
R = rand(); % in [0,1]
parent1_idx = M;
for i = 1: length(cumsum)
if R > cumsum(i)
parent1_idx = i – 1;
break;
end
end
parent2_idx = parent1_idx;
while_loop_stop = 0;
while parent2_idx == parent1_idx
while_loop_stop = while_loop_stop + 1;
R = rand(); % in [0,1]
if while_loop_stop > 20
break;
end
for i = 1: length(cumsum)
if R > cumsum(i)
parent2_idx = i – 1;
break;
end
end
end
parent1 = temp_population.Chromosomes(parent1_idx);
parent2 = temp_population.Chromosomes(parent2_idx);
end

Best Answer

It appears that you are using your own genetic algorithm code, rather than the ga function. The only problem is with the timeseries object.
There does not appear to be any way to calculate using timeseries objects (they appear to be data collection objects only, I have no experience with them), so it would likely be best to extract the data to a matrix and just use the matrix.