Help with gridsearch

archdukearchduke Rome
edited November 2010 in Nerdery
Hi guys, Ihave some problems with my matlab code, hope that someone can help me out. Any suggestion would be precious!

here's what i'm doing: I wrote a script that should help me discriminating two signals,
at the end of the script I have a score, which is an entropic score: i suppose that signals
with a regular behaviour (e.g. similar to sinusoids) have a lower entropy, while signal with
a lot of disorder have a larger entropy instead. By the way, I store this entropic score
into b2 (score = b2(k,l,m,p);), a 4-d matrix, and this score depends on 3 parameters, which are
l, m and p. K is the number of examples i have in the dataset.
Now, i have to discriminate between the two signals. Running a gridsearch, i search for the best
combination of l,m and p that helps me having high scores for messed-up signals and low ones for
"ordered" signals.
I've tried many times, also maximizing variables like matthew's correlation, F1, F1+F0 etc..
It seems i have a limit in some way. I can't obtain good results.
Anything to suggest or errors you notice in my code?
Your help would be really appreciated, here's the code (hope i've posted it correctly):
start_dec = min(min(min(min(b2))));
dec_step = 0.01;
max_dec = 1;

for p=round(start_alpha/step_alpha):round(max_alpha/step_alpha)
    for m=round(start_delta/step_delta):round(start_alpha/step_alpha)
        for l=round(start_kern/step_kern):round(start_kern/step_kern)
            for dec=start_dec:dec_step:max_dec
                
                tp=0;
                fp=0;
                tn=0;
                fn=0;
                                             
                predicted_pos = 0;
                predicted_neg = 0;
                                            
                f0 = 0; 
                f1 = 0;
                                            
                p0 = 0; 
                p1 = 0; 
                                            
                r0 = 0; 
                r1 = 0; 
                
                for k=1:1:llist
                    
                    score = b2(k,l,m,p);
                     
                    if score > dec
                        predicted_neg=predicted_neg+1;
                        if TrainingStatus(k)==0;
                            tn=tn+1;
                        else
                            fn=fn+1;
                        end
                        else
                        predicted_pos=predicted_pos+1;
                        if TrainingStatus(k)==1;
                            tp=tp+1;
                        else
                            fp=fp+1;
                        end
                    end
                end
                
                if predicted_neg > 0
                    p0 = tn./predicted_neg;
                else
                    p0=0;
                end
                if predicted_pos > 0
                    p1 = tp./predicted_pos;
                else
                    p1=0;
                end
                
                r1 = tp/total_positives(1,1);
                r0 = tn/total_negatives(1,1);
                
                if (p0+r0) > 0
                    f0 = 2*p0*r0./(p0+r0);
                else 
                    f0 = 0;
                end
        
                if (p1+r1) > 0
                    f1 = 2*p1*r1./(p1+r1);                                                                 
                else 
                    f1 = 0;
                end
                                                    
                matthws = (tp*tn-fp*fn)./sqrt((tp+fp)*(tp+fn)*(tn+fp)*(tn+fn));
                   
        
                correct = f1;
                
                
                if correct(1,1) > max_correct 
                
                    max_correct = correct;
                    best_kernel = l;
                    best_alpha = p;
                    best_delta = m;
                    best_dec = dec;

                    best_tp = tp;   
                    best_fp = fp;
                    best_fn = fn;           
                    best_tn = tn;    
                    best_matth = matthws;

                    best_p0 = best_tn./predicted_neg;
                    best_p1 = best_tp./predicted_pos;
                    best_r0 = best_tp/total_positives(1,1);
                    best_r1 = best_tn/total_negatives(1,1);


                    best_f0 = 2.0*best_p0*best_r0/(best_p0+best_r0);
                    best_f1 = 2.0*best_p1*best_r1/(best_p1+best_r1);    
                end
                
            end
        end
    end
end

</code></code><code style="white-space: nowrap;"><code>
</code></code>
Sign In or Register to comment.