-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateGuessesMono.m
74 lines (74 loc) · 2.65 KB
/
generateGuessesMono.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function [M, function_name] = generateGuessesMono(func_guess, range, num_poly, verbose, multiply)
syms x;
num_func = length(func_guess);
if verbose
fprintf('Evaluating function-guesses');
end
sequences = cellfun(@(j) cellfun(@(i) subs(func_guess{j}, x, sym(i)), range), num2cell(1:num_func), 'UniformOutput', false);
if verbose
fprintf('\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b');
disp('Finished evaluating function-guesses');
if multiply
fprintf('Calculating product-functions');
end
end
M(1:num_func, :) = vertcat(sequences{:});
current_row = num_func + 1;
N = length(sequences);
if multiply
% Adding f*g if f and g are in the input
counter = 1;
prod_func = cell(1, (N*N-N)/2);
for i = 1:N
for j = i+1:N
M(current_row, :) = M(i, :) .* M(j, :);
current_row = current_row + 1;
prod_func{counter} = func_guess{i} * func_guess{j};
counter = counter + 1;
end
end
func_guess = [func_guess, prod_func];
end
if verbose
if multiply
fprintf('\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b');
disp('Finished calculating product-functions');
end
fprintf("Calculating polynomes");
end
% Calculating polynomes up to the degree "rec_degree"
polynomes = cell(1, num_poly);
poly_name = cell(1, num_poly);
if num_poly >= 1
polynomes{1} = cellfun(@(i) 1, range);
poly_name{1} = 1;
end
for j=1:num_poly-1
polynomes{j+1} = cellfun(@(i) sym(i)^j, range);
poly_name{j+1} = sym(x)^j;
end
polyMatrix = vertcat(polynomes{:});
if verbose
fprintf('\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b');
disp('Finished calculating polynomes');
fprintf("Calculating function-polynom products");
end
% Adding f*p for f is in the input and p is a polynom previous
% calculated
counter = 1;
function_name = cell(1, (current_row-1)*(num_poly-1));
for i = 1:(current_row-1)
for j= 2:num_poly
M(current_row, :) = M(i, :) .* polyMatrix(j, :);
current_row = current_row + 1;
function_name{counter} = func_guess{i} *poly_name{j};
counter = counter + 1;
end
end
M(current_row:current_row + num_poly - 1, :) = polyMatrix;
function_name = [func_guess, function_name, poly_name];
if verbose
fprintf('\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b');
disp("Finished calulating function-values");
end
end