# Weighted_similarity and tabu search

``````data = [["O", "U", "V", "buss", "bsh"], ["NA", "hand", "machine", "other", "mis"],
["NA", "simple", "medium", "full", "mis"], ["NA", "shoulder-elbow", "elbow", "elbow-wrist", "wrist"],
["NA", "curfed", "relaxed", "extended", "mis"], ["fited", "semi-fitted", "loose", "mis", "mis"]]

function weighted_similarity(x::Vector{Vector{String}}, y::Vector{Vector{String}}, weights::Vector{Float64})
sim = 0.0
for i in 1:length(weights)
if weights[i] != 0 && (i <= length(x) && i <= length(y))
if x[i] == y[i]
sim += weights[i]
end
end
end
return sim
end

function tabu_search(data::Vector{Vector{String}}, weights::Vector{Float64}, tabu_tenure::Int, max_iterations::Int, m::Int)
# best_solution = randperm(n)
best_solution = data[randperm(m)]
n = length(data)
best_fitness = -Inf
current_solution = best_solution
current_fitness = -Inf
tabu_list = zeros(Int, n, n)

iter = 0
for iter in 1:max_iterations
neighbors = []
for i in eachindex(1:n)
for j in i+1:n
if tabu_list[i, j] == 0
neighbor = copy(current_solution)
neighbor[i], neighbor[j] = neighbor[j], neighbor[i]
push!(neighbors, neighbor)
end
end
end

if isempty(neighbors)
break
end

neighbor_fitnesses = [weighted_similarity(neighbors[i], current_solution, weights) for i in 1:length(neighbors)]
best_neighbor_fitness, best_neighbor_index = findmax(neighbor_fitnesses)

if best_neighbor_fitness > current_fitness
current_solution = neighbors[best_neighbor_index]
current_fitness = best_neighbor_fitness

if current_fitness > best_fitness
best_solution = current_solution
best_fitness = current_fitness
end
end
append!(tabu_list, [[best_slution]])

for i in 1:n-1
for j in i+1:n
if tabu_list[i, j] > 0
tabu_list[i, j] -= 1
end
end
end

i, j = findmin(tabu_list)
if tabu_list[i, j] == 0
tabu_list[i, j] = tabu_tenure
end
end
return (best_solution, best_fitness)
end

got  the error;

ERROR: BoundsError: attempt to access 10-element Vector{Vector{String}} at index [11]
Stacktrace:
[1] getindex(A::Vector{Vector{String}}, i1::Int64)
@ Base .\array.jl:924
[2] t_search(data::Vector{Vector{String}}, weights::Vector{Float64}, tabu_tenure::Int64, max_iterations::Int64, m::Int64)
@ Main c:\Users\Account\ml_model\project.jl:136
[3] top-level scope
@ c:\Users\Account\ml_model\project.jl:271
``````

I am trying to reduce features for my clustering model. I am stuck because of the error. Please, can someone help me out?