Question

In: Electrical Engineering

MATLAB CODE FOR E xtreme learning machine using for classification task. image processing electrical. if you...

MATLAB CODE FOR

E xtreme learning machine using for classification task.

image processing electrical.

if you know then try or leave for other

Solutions

Expert Solution

clc;
clear;
close all;
II=imread('lena.tiff');
% I2=rgb2gray(II);
I2=II(:,:,3);
% figure;
% imshow(I2)
I=double(I2);
% I=I2;
%step1
LH{1}=I;
for i=2:5
[LA{i},LH{i},LV{i},LD{i}] = lwt2(LH{i-1},'haar');
end
LL4=LA{5};
C(:,1)=(reshape(LL4,1,1024))';
C(:,2)=(round(reshape(LL4,1,1024)/32))';
function [output_wt,TrainingAccuracy,TestingAccuracy,correctClassifiedSamples_Testing]=my_elm(training_data,testing_data, output_train,output_test,numberHidden)
%%Input arguments


function [output_wt,TrainingAccuracy,TestingAccuracy,correctClassifiedSamples_Testing]=my_elm(training_data,testing_data, output_train,output_test,numberHidden)
%%Input arguments
%training_data=N1*d (N1=# of training samples, N2=# of testing samples)
%output_train=N1*c (c= # of clases, d= feature dimension)
%testing_data=N2*d
%output_test=N2*c
start_time_train=cputime;
d=size(training_data,2);
training_data(:,d+1)=1; % input bias added in last column
%% input weight and bias (last column) initialization
inputWeightBias=rand(size(training_data,2),numberHidden)*0.0001;
%inputWeightBias=rand(size(training_data,2),numberHidden)*2-1; %a in [-1,1]
aa=inputWeightBias;
%a=rand(size(training_data,2),numberHidden)*2-1; %a in [-1,1]
H_final=[];
for i=1:size(training_data,1)
    h=inputWeightBias'*training_data(i,:)';
    H = 1 ./ (1 + exp(-h));% sigmoid trans func
    %H=h;
    %H=sin(h); % sine tf
    %H=radbas(h); % Radial basis function tf
    H_final=[H_final;H'];
    clear H;

end
output_wt=pinv(H_final)*output_train; % calculated output weight (beta)
end_time_train=cputime;
TrainingTime=end_time_train-start_time_train
%% Calculate the training accuracy
actual_output=H_final*output_wt; %the calculated output of the training data
correctClassifiedSamples_Training=0;
for i = 1 : size(output_train, 1)
        [x, index_desired_label]=max(output_train(i,:));
        [x, index_actual_label]=max(actual_output(i,:));
        if index_actual_label==index_desired_label
            correctClassifiedSamples_Training=correctClassifiedSamples_Training+1;
        end
end
    TrainingAccuracy=correctClassifiedSamples_Training/size(output_train,1)
%% testing part
start_time_test=cputime;
d1=size(testing_data,2);
testing_data(:,d1+1)=1; % input bias added in last column
H_final_test=[];
for i=1:size(testing_data,1)
    h_test=aa'*testing_data(i,:)';
    H_test = 1 ./ (1 + exp(-h_test));% sigmoid trans func
    %H_test=h_test;
    %H_test=sin(h_test); % sine tf
    %H_test=radbas(h_test); % Radial basis function tf
    H_final_test=[H_final_test;H_test'];
    clear H_test;
end
%% Calculate the testing accuracy
actual_output_test=H_final_test*output_wt; %the calculated output of the testing data
end_time_test=cputime;
TestingTime=end_time_test-start_time_test

correctClassifiedSamples_Testing=0;
for i = 1 : size(output_test, 1)
        [x, index_desired_label]=max(output_test(i,:));
        [x, index_actual_label]=max(actual_output_test(i,:));
        if index_actual_label==index_desired_label
            correctClassifiedSamples_Testing=correctClassifiedSamples_Testing+1;
        end
end
    TestingAccuracy=correctClassifiedSamples_Testing/size(output_test,1)
end

if you have any doubt feel free to ask in comments.


Related Solutions

MATLAB code: using Laplacian mask enhance for image "ngc6543.jpg".
MATLAB code: using Laplacian mask enhance for image "ngc6543.jpg".
I am writing this machine learning code (classification) to clssify between two classes. I started by...
I am writing this machine learning code (classification) to clssify between two classes. I started by having one feature to capture for all my images. for example: class A=[(4295046.0, 1), (4998220.0, 1), (4565017.0, 1), (4078291.0, 1), (4350411.0, 1), (4434050.0, 1), (4201831.0, 1), (4203570.0, 1), (4197025.0, 1), (4110781.0, 1), (4080568.0, 1), (4276499.0, 1), (4363551.0, 1), (4241573.0, 1), (4455070.0, 1), (5682823.0, 1), (5572122.0, 1), (5382890.0, 1), (5217487.0, 1), (4714908.0, 1), (4697137.0, 1), (4737784.0, 1), (4648881.0, 1), (4591211.0, 1), (4750706.0, 1), (5067788.0, 1),...
How do I implement Image Processing using VHDL for FPGA? Please provide VHDL code
How do I implement Image Processing using VHDL for FPGA? Please provide VHDL code
1.Is classification consider Supervised or Unsupervised Learning?Explain. 2.Suppose you are given the task of finding a...
1.Is classification consider Supervised or Unsupervised Learning?Explain. 2.Suppose you are given the task of finding a useful training dataset for a Classification problem you have been assigned.Suppose you find the features but dataset dose not include the labels.Briefly explain how you might label the data for the use Classification. 3.What does the sample() function in R do ?
Deep leraning/LSTM/Matlab There is a Matlab code that is doing the following steps for deep learning...
Deep leraning/LSTM/Matlab There is a Matlab code that is doing the following steps for deep learning and applying LSTM, I need to change first three steps to use our dataset to train this model and you don't need to change other. I need to apply that for .ogg audio files so Create and Use some audio files with .ogg format as sample data and give me the code. The following steps is for your information: Three classes of audio signals...
What are some of the challenges to studying art classification in machine learning?
What are some of the challenges to studying art classification in machine learning?
Using Matlab 1. Create a color image of size 200 × 200. The image should have...
Using Matlab 1. Create a color image of size 200 × 200. The image should have a blue background. 2. Create 100 yellow regions within the image that have a variable size. More specifically, their width should be an odd number and vary between 3 and 7 and their height should also be an odd number and vary between 3 and 7. For example, you may get rectangular regions of size 3 × 3, 3 × 5, 5 × 3,...
Discuss and state the Learning Journal question/task and its requirements. View the following image, The Eat...
Discuss and state the Learning Journal question/task and its requirements. View the following image, The Eat Well Plate, and answer the following questions in your learning journal. 1. Recall what you had to eat for your last meal and list where they appear in the Eat Well Plate. 2. Do you think that this “Eat Well Plate” is a plate that you would be able to have for every meal? In other words, is it possible to for people to...
Draw a Koch Snowflake fractal image using MATLAB programming. I'm pretty new to MATLAB and im...
Draw a Koch Snowflake fractal image using MATLAB programming. I'm pretty new to MATLAB and im not too familar with how all the plotting and drawing functions work.
I want to create an image compression program with matlab use PCA. I have the code...
I want to create an image compression program with matlab use PCA. I have the code listed below. But this code is fail, the image is colorless, but still gray. Can you help me to fix my code. clc clear all picture = im2double(imread('picture1.jpg')); Red = picture(:,:,1); premean = mean(Red(:)); premax = max(Red(:)); premin = min(Red(:)); x = size(Red,1); y = size(Red,2); Z = ones(x,y)*premean; A = (Red - Z)*(1/premax - premin); B = cov(A); [veceig,eig,C] = pcacov(B); NewRed =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT