Tuesday, 4 September 2018

Gradient Descent


2.2 Gradient Descent
In this part, you will fit the linear regression parameters θ to our dataset using gradient descent.
ARS NOTLARI:
Bu bölümde amaç şehir nüfusu seçildiğinde kârın ne olacağını tahmin etmektir. Elimizdeki şehir nüfusu değerleri ve onlara ait kâr miktarları arasında  y = a + bx şeklinde doğrusal bir ilişki kurabilirsek X değerini seçtiğimizde buna karşı düşen kâr miktarını bulabiliriz.  

Burada sorun elimizdeki kâr değerlerinin doğrusal bir dağılıma sahip olmamasıdır.  Öyle ise amacımız eldeki tüm verileri dikkate alan, toplamda mümkün olan en haz hatalı doğruyu bulmaktır.   
Hinton’un  bahsettiği linear regression parameters θ(doğrusal ilişki parametreleri) y= a + bx doğrusal denklemindeki a ve b değerleridir.

Figure 1: Scatter plot of training data LG1

2.2.1 Update Equations
The objective of linear regression is to minimize the cost function
 

where the hypothesis hθ(x) is given by the linear model
 (y = a + bx  a= θ0 , b= θ1
ARS NOTLARI:
Seçtiğimiz a ve b değerlerine göre oluşan doğru üzerindeki değerler ile gerçek kâr değerleri arasındaki
farkların toplamı yaptığımız a ve b seçiminin maliyetini verir.  Bu toplama maliyet fonksiyonu(cost function)’u  denir.  Kurmaya çalıştığımız doğrusal ilişki’nin amacı maliyet fonksiyonu(cost function)’nu  mümkün olan en küçük değere indirmektir.
Yukarıda J(θ) seçtiğimiz θ değerlerine göre değişen maliyeti gösterir.
h0(xi)  seçtiğimiz ilk doğruyu  şehir nüfusuna göre x’in aldığı değerleri belirtir.
( h0(xi) - yi )2 seçtiğimiz ilk doğruya göre bulunan kâr değerleri ile yi gerçek kâr değerleri arasındaki
farktır.

Burada amaç seçilecek her doğru için bu hesaplamayı yaparak en uygun doğruyu bulmaktır.
Hinton’un bahsettiği model bu doğru ve onun denklemidir.

Recall that the parameters of your model are the θj values. These are the values you will adjust to minimize cost J(θ). One way to do this is to use the batch gradient descent algorithm.
Modelinizin parametrelerinin θj değerleri olduğunu hatırlayınız.  Bunlar J(θ) maliyeti minimize etmek için ayarlayacağımız değerlerdir.  Bu ayarlamayı yapmanın bir yolu gradient descent algoritmasıdır.

In batch gradient descent, each iteration performs the update
 


With each step of gradient descent, your parameters θj come closer to the
optimal values that will achieve the lowest cost J(θ)
Batch gradient descent algoritmasında her adım yukarıdaki güncellemeyi yapar. Gradient descent’in her adımıyla, θj parametreleriniz en düşük maliyeti sağlayacak optimal değerlere yaklaşacaktır.

ARS NOTLARI:
θj değeri  j’inci iterasyonda θ’nın aldığı değerdir.  θj yeni değerini bulmak için,  ( h0(xi) - yi )2 ‘nin türevi nin bütün şehirlerde aldığı değerlerin toplamını gene bütün şehirlerin sayısına bölüp bir yaklaşma hızı alfa ile çarparak, θj’nin eski değerinden  çıkartır.  Alfanın büyüklüğü sonuca yakınsama hızını etkilediği gibi fazla büyük alınırsa sonucu atlayıp ıraksamaya da yol açabilir.
Şekildeki  j indisi θj gradien descent hesaplama, yakınsama adımını, iterasyonu belirtir.  x(i) y(i) ‘deki i değişkeni ise geçmişte ölçüm yapılmış şehir nüfusu-kâr ikililerini belirtir.  Her θj yeni bir y = a + bx  a= θ0 , b= θ1 doğrusunu belirtir.  Amacımız bütün denek noktaları dikkat alındığında bu noktalara en yakın optimal geçen θ)= θ01x doğrusunu bulmaktır.

Implementation Note: We store each example as a row in the the X matrix in Octave. To take into account the intercept term (θ0), we add an additional first column to X and set it to all ones. This allows us to treat θ0 as simply another ‘feature’.
Uygulama Notu: Octave’de Xmatrixi içinde her örnek değeri bir satıra saklıyoruz.  (θ0), intercept terimini hesaba katmak için, X’e ek bir birinci sütun ekliyoruz ve satırlarının hepsinin değerlerini 1 yapıyoruz.  Bu bizim (θ0)’a bir  başka’ özellik’ gibi muamele etmemizi sağlıyor.


2.2.2 Implementation
In ex1.m, we have already set up the data for linear regression. In the following lines, we add another dimension to our data to accommodate the θ0 intercept term. We also initialize the initial parameters to 0 and the learning rate alpha to 0.01.

X = [ones(m, 1), data(:,1)];         % Add a column of ones to x
theta = zeros(2, 1);
 % initialize fitting parameters
iterations = 1500;
alpha = 0.01;
ex1.m’de doğrusal ilişki için veriyi hazırlamış bulunuyoruz.  Aşağıdaki satırlarda verimize intercept deyimini yerleştirmek için yeni bir sütun ekliyoruz.  Ayrıca başlangıç parametrelerinide 0 ve öğrenme oranı alpha’yı da 0.01 yapıyoruz.

ARS NOTLARI:
X = [ones(m, 1), data(:,1)];   Burada m elde bulunan şehir nüfusu/kâr değerlerinin (öğrenme seti) sayısıdır.
octave:1> data=[1,2;3,4;5,6]
data =
   1   2
   3   4
   5   6
octave:2> m=size(data,1)
m =  3
octave:3> ones(m,1)
ans =
   1
   1
   1
octave:4> data(:,1)
ans =
   1
   3
   5
octave:5> X=[ones(m, 1), data(:,1)];
octave:6> X
X =
   1   1
   1   3
1         5

2.2.3 Computing the cost J(θ)
As you perform gradient descent to learn minimize the cost function J(θ), it is helpful to monitor the convergence by computing the cost. In this section, you will implement a function to calculate J(θ) so you can check the convergence of your gradient descent implementation.
J(θ) Maliyet fonksiyonunu minimize etmeyi öğrenmek için Gradient descent’i çalıştırırken,  o durumdaki  maliyeti hesaplarak yakınsamayı izlemek faydalı olabilir.  Bu kısımda, J(θ)’yı hesaplamak için bir fonksiyon yapacaksınız, öyle ki yaptığınız gradient descent’ in yakınsamasını kontrol edebileceksiniz.

The variables X and y are not scalar values, but matrices whose rows represent the examples from the training set.
X ve y değişkenleri sayı değerleri değil, satırları öğrenme setinin örnekleri olan vektörlerdir.

ARS NOTLARI:
Maliyet, sistemde yapılacak küçük bir değişikliğin sistem çıktısında oluşturacağı değişikliktir.  Bu değişiklik olumlu yönde olabildiği gibi olumsuz yönde  de olabilir.  Bizim amacımız, elimizdeki öğrenme verilerinin hepsini kullanarak, deneme amaçlı seçtiğimiz doğrunun olumlu bir seçim olup olmadığını kontrol etmektir.  İşte bu amaç için maliyeti kontrol eden  J(θ) fonksiyonunu geliştireceğiz.

computeCost.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function J = computeCost(X, y, theta)
%COMPUTECOST Compute cost for linear regression
%   J = COMPUTECOST(X, y, theta) computes the cost of using theta as the
%   parameter for linear regression to fit the data points in X and y
ARSnotlar:
Ana programımız ex1 computeCost.m içinde duran harici  computeCost fonksiyonunu çağırır.
Maliyeti hesaplamak için X şehir nüfusları bilgileri vektörü, y bu şehir-nüfusları için kâr miktarları ve
Maliyetini ölçmek istediğimiz doğruyu belirten θ= θ01x vektörünü çağırdığımız computeCost fonksiyonuna geçirmemiz gerekir.  Unutmayınız ki X vektörüne intercept sütunu eklemiş durumdayız.

% Initialize some useful values
m = length(y);    % number of training examples

% You need to return the following variables correctly
J = 0;  % J maliyete başlangıç olarak 0 değerini veriniz.

% ============================================
% Instructions: Compute the cost of a particular choice of theta
%               You should set J to the cost.

% Loop implementation
%for i = 1:m,
%            J = J + (((X(i,:) * theta) - y(i)) ^ 2);
%end;
ARSnotları:
m  şehir nüfusları/bunlara karşı düşen kâr miktarları şeklinde elimizde bulunan öğrenme amaçlı ikililerin sayısını belirtir.  Dolayısıyla m defa  J = J + (((X(i,:) * theta) - y(i)) ^ 2); işlemi yapılacak
ve her defasında defa  J = J + ...  şeklinde daha önceki şehir-nüfuslarından kalan maliyet biriktirilecek ve toplam maliyet bulunacaktır. Theta’nın ilk değeri yukarıda
theta = zeros(2, 1);
0+0x ve boyutu 2 x 1  şeklinde verilmişti.
X ise X = [ones(m, 1), data(:,1)];     Burada m şehir-nüfus öğrenme örnekleri sayısı,
ones(m, 1),  θ01x’in θ0 intercepti nedeniyle eklenmiş sütun ,
data(:,1) ise şehir-nüfus değerlerini içeren input verisidir.
X m x 2 boyutundadır.

Böylece yukarıda vermiş olduğumuz maliyet fonksiyonunu gerçekleştirmiş oluruz.
% Vectorized implementation

J = sum(((X * theta) - y) .^ 2); 

J = 1 / (2 * m) * J;   % J= 32.073

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 Once you have completed the function, the next step in ex1.m will run computeCost once using θ initialized to zeros, and you will see the cost printed to the screen. You should expect to see a cost of 32.07. 

% compute and display initial cost
computeCost(X, y, theta)

Bir kere bu fonksiyonu tamamladıktan sonraki adım:  computeCost’u bir defa θ’ya başlangıçta 0 değerlerini vererek  çalıştıracaksınız, ve maliyetin ekrana yazıldığını göreceksiniz.  32.07 maliyetini görmeniz gerekir.




2.2.4 Gradient descent
Next, you will implement gradient descent in the file gradientDescent.m. The loop structure has been written for you, and you only need to supply the updates to θ within each iteration.
Daha sonra, gradientDescent.m dosyası içindeki gradient descent’i yapacaksınız. 

As you program, make sure you understand what you are trying to optimize and what is being updated. Keep in mind that the cost J(θ) is parameterized by the vector θ, not X and y. That is, we minimize the value of J(θ) by changing the values of the vector θ, not by changing X or y.
Neyi optimize ettiğinizi ve neyin güncellendiğini anladığınızdan emin olunuz.  Maliyet J(θ) ‘nın parametresi θ’dır, X ve y değil.  Yani  J(θ) değerini θ  vektörünün değerlerini değiştirerek minimize ediyoruz,  X ve y ‘yi değil.
A good way to verify that gradient descent is working correctly is to look at the value of J(θ) and check that it is decreasing with each step.
Bir gradient descent’in doğru çalıştığını kontrol etmenin iyi bir yolu J(θ) ‘nın değerine bakıp her iterasyon adımında azaldığını gözlemektir.

The starter code for gradientDescent.m calls computeCost on every iteration and prints the cost.
Başlangıçta gradientDescent.m  için verilen kod  her iterasyonda computeCostu çağırır ve maliyeti yazar.

% run gradient descent
theta = gradientDescent(X, y, theta, alpha, iterations);

% print theta to screen
fprintf('Theta found by gradient descent: ');
fprintf('%f %f \n', theta(1), theta(2));

ARSnotları:
gradientDescent fonksiyonu kendisini çağıran yere theta vektörünü 2 x 1 döndürür.
Alpha öğrenme hızını belirler.
İterations toplam iterasyon sayısını verir.
Çıktı yazdırılırken theta(1), theta(2)); θ01x değerlerini verir.
gradientDescent.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters)
%GRADIENTDESCENT Performs gradient descent to learn theta
%   theta = GRADIENTDESENT(X, y, theta, alpha, num_iters) updates theta by
%   taking num_iters gradient steps with learning rate alpha

% Initialize some useful values
m = length(y); % number of training examples
J_history = zeros(num_iters, 1);
ARSnotları:
m değişkeni  y kâr değerlerinin sayısıdır, bu aynı zamanda X şehir-nüfus değerlerinin sayısıdır.
Maliyet değerlerini  J_history vektörü içinde saklıyacağız, bunun uzunluğu toplam iterasyon sayısına (num_iters) eşittir.

for iter = 1:num_iters

    % ====================== YOUR CODE HERE ======================
    % Instructions: Perform a single gradient step on the parameter vector
    %               theta.

                % Nested loop implementation:
                % num_thetas = length(theta);  % theta vektörünün uzunluğu
                % theta_new = zeros(num_thetas,1);  % sonuç theta vektörü başlangıç theta ile aynı boyutta
                % for j = 1:num_thetas
                %            inner_sum = 0;
                %            for i = 1:m
                %                            inner_sum = inner_sum + ((X(i,:) * theta) - y(i)) * X(i,j);
                %            end
                %            theta_new(j) = theta(j) - (alpha / m * inner_sum);
                %end
ARSnotları:
% inner_sum = 0;
                %            for i = 1:m
                %                            inner_sum = inner_sum + ((X(i,:) * theta) - y(i)) * X(i,j);
                %            end
Yukarıda, % Loop implementation kısmında açıklanmıştı.
+ ((X(i,:) * theta) - y(i)) * X(i,j); değerleri  for i=1:m çevrimi içinde bütün şehir-nüfus değerleri
Ve bunlara ilişkin kâr değerleri için inner_sum içinde toplanır.
Bu işlem % for j = 1:num_thetas çevrimi içinde bütün  θ değerleri01x) için tekrarlanarak sonuç theta(j) - (alpha / m * inner_sum  ile hesaplanıp theta_new (j) içine konur.

    % Vectorized implementation:
                A = X * theta - y;                             % (m x 1 vector)   97 x 2 * 2 x 1  -  97 x 1
                delta = 1 / m * (A' * X)';                % ' ((n+1) x 1 vector)  (1 x 97 * 97 x 2)' = 2 x 1
                theta = theta - (alpha * delta);                 % ' ((n+1) x 1 vector) 2 x 1 - (alpha * 2 x 1)
                % printf(' tttt %s \r\n',"ARS");
                % printf('%4f \r\n',iter);
                 
    % ============================================================
ARSnotları:
X şehir-nüfus değerleri sayısı 97’dir.  X vektörüne bir sütun intercept eklemiştik.  Bunun amacı
θ01x ile uyumluluk sağlamaktır.  X * theta, 97 x 1 sonucu verir. Bundan kâr değerlerinin vektörünü (97 x 1) çıkartırız.

Delta  = 1 / m * (A' * X)'; yukarıda açıklanan

formulünden geliyor.  Özü, değişim miktarının ait olduğu değerle çarpılarak bütün bu çarpımların toplanması ve bütün değerlerin sayısına bölünmesine dayanır.

Bütün değerler vektör satırlarında ifade edildiği ve dikkate alındığı için bir çevrim gerekmemektedir.

    % Save the cost J in every iteration   
    J_history(iter) = computeCost(X, y, theta);

end
fprintf(' num_iters: %4.2f \r\n', num_iters);

end
ARSnotları:
Hesaplanan maliyet değerleri  iterasyon sayısı bazında    J_history(iter)’ye yazılır.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Assuming you have implemented gradient descent and computeCost correctly, your value of J(θ) should never increase, and should converge to a steady value by the end of the algorithm.
Eğer gradient descent ve computeCost’u doğru yaptıysanız  J(θ) değeriniz hiç bir zaman artmamalıdır, ve algoritma sonunda sabit bir değere yakınsamalıdır.

After you are finished, ex1.m will use your final parameters to plot the linear fit. The result should look something like Figure 2:
Bitirdikten sonra ex1.m son olarak ulaştığınız parametre değerlerini kullanır.  Sonuç şekil 2 deki gibi olmalıdır.

% Plot the linear fit
hold on;            % keep previous plot visible % eski şekli koru
plot(X(:,2), X*theta, '-') 
legend('Training data', 'Linear regression')
hold off          % don't overlay any more plots on this figure %bu şekil üzerine yeni noktalar koyma

Bulduğunuz en son  θ değerleri (yani doğrunun a+bx) katsayıları  35,000 ve 70,000 kişilik şehirlerde kârın ne olacağını tahmin etmek için kullanılır.

% Predict values for population sizes of 35,000 and 70,000
predict1 = [1, 3.5] *theta;
fprintf('For population = 35,000, we predict a profit of %f\n', predict1*10000);
predict2 = [1, 7] * theta;  % 1 x 2 * 2 x 1 = 1 x 1
fprintf('For population = 70,000, we predict a profit of %f\n',   predict2*10000);

2.3 Debugging
Here are some things to keep in mind as you implement gradient descent:   Octave array indices start from one, not zero. If you’re storing θ0 and θ1 in a vector called theta, the values will be theta(1) and theta(2).
Gradient descenti yaparken akılda tutmanız gereken birkaç şey:  Octave dizi(array) indexleri 1’den başlar, 0’dan değil.  Eğer θ0 ve θ1’i theta isimli bir vektöre saklıyorsanız değerleri theta(1) ve theta(2) olacaktır.

ˆ If you are seeing many errors at runtime, inspect your matrix operations to make sure that you’re adding and multiplying matrices of compatible dimensions. Printing the dimensions of variables with the size command will help you debug.
Programı çalıştırıken çok sayıda hata görüyorsanız, toplama ve çarpma yaptığınız matrislerin uyumlu boyutlara sahip olduğundan emin olmak için, matris işlemlerinizi gözden geçiriniz.  Değişkenlerin boyutlarını size komutu ile yazdırmanız hataları bulmanıza yardımcı olacaktır.


Figure 2: Training data with linear regression fit  LG2

ˆ By default, Octave interprets math operators to be matrix operators. This is a common source of size incompatibility errors. If you don’t want matrix multiplication, you need to add the “dot” notation to specify this to Octave. For example, A*B does a matrix multiply, while A.*B does an element-wise multiplication.
Default olarak, Octave matematik operatörlerini matrix operatörü olarak yorumlar.  Bu, uyumsuzluk hatalarının genel bir kaynağıdır.  Eğer matrix çarpımı istemiyorsanız, ‘nokta’ notasyonunu kullanınız.
2 * 2 yarine 2 .* 2   a *b yerine a .* b

Saturday, 1 September 2018

Basit Doğrusal İlişki nedir


Edited by Ali R+ SARAL from Onlinecourses.science.psu.edu  STAT 501

1.1      - What is Simple Linear Regression?
Basit Doğrusal İlişki nedir?

Simple linear regression is a statistical method that allows us to summarize and study relationships between two continuous (quantitative) variables:
Basit doğrusal ilişki iki sürekli(sayısal) değişken arasındaki ilişkileri özetlememizi ve incelememizi mümkün kılan istatistiksel bir yöntemdir:

§  One variable, denoted x, is regarded as the predictor, explanatory, or independent variable.
Bir değişken, x ile gösterilip, öngörücü, açıklayıcı veya bağımsız değişken olarak görülür.

§  The other variable, denoted y, is regarded as the response, outcome, or dependent variable.
Diğer değişken, y ile gösterilip yanıt, sonuç, bağımlı değişken olarak görülür.

...
 Simple linear regression gets its adjective "simple," because it concerns the study of only one predictor variable.
Basit doğrusal ilişki ‘basit’ sıfatını yalnız bir değişkenin incelenmesi ile ilgili olduğu için alır.
...
Types of relationships
İlişki Tipleri

Before proceeding, we must clarify what types of relationships we won't study in this course, namely, deterministic (or functional) relationships. Here is an example of a deterministic relationship.
Daha fazla ilerlemeden, bu kursta hangi tip ilişkileri ele almayacağımızı belirtelim, belirleyici(deterministic) ya da fonksiyonel(functional) ilişkiler.  İşte bir belirleyici ilişki örneği.
Note that the observed (x, y) data points fall directly on a line. As you may remember, the relationship between degrees Fahrenheit and degrees Celsius is known to be:
Fahr =95Cels+32Fahr =95Cels+32
Gözlenen(x,y) veri noktaları doğrudan bir doğru üzerine düşmekte. Fahrenheit ve Celcius arasındaki ilişki hatırlayacağınız gibi:
Fahr =95Cels+32Fahr =95Cels+32



That is, if you know the temperature in degrees Celsius, you can use this equation to determine the temperature in degrees Fahrenheit exactly.
Yani, eğer Celcius cinsinden dereceyi biliyorsanız, bu formulü kullanarak Fahrenheit cinsinden sıcaklığı tam olarak bulabilirsiniz.
§  ...
For each of these deterministic relationships, the equation exactly describes the relationship between the two variables. ...
Herbir belirleyici ilişki için, eşitlik iki değişken arasındaki ilişkiyi tam olarak tarif eder.

Instead, we are interested in statistical relationships, in which the relationship between the variables is not perfect.
Bunun yerine, biz değişkenler arasındaki ilişkinin ideal olmadığı, istatistiksel ilişki ile ilgileniyoruz.

Here is an example of a statistical relationship. The response variable y is the mortality due to skin cancer, the predictor variable x is the latitude (degrees North) at the center of each of 49 states in the U.S ...
İşte istatistiksel ilişkiye bir örnek. y değişkeni deri kanserine bağlı ölüm sayılarını x değişkeni ABD’deki  49 devletin tam ortalrından geçen boylamları belirtir.

You might anticipate that if you lived in the higher latitudes of the northern U.S., the less exposed you'd be to the harmful rays of the sun, and therefore, the less risk you'd have of death due to skin cancer.
Eğer ABD’nin daha kuzey bölgelerinde yaşıyorsanız, tehlikeli güneş ışınlarına daha çok maruz kalacağınızı, böylece deri kanserinden ölümlerin daha fazla olacağını öngörebilirsiniz.

The scatter plot supports such a hypothesis. There appears to be a negative linear relationship between latitude and mortality due to skin cancer, but the relationship is not perfect.
Dağınık noktalama şekli bu hipotezi desteklemektedir.  Deri kanseri ile ölümlerde boylam ile karşıt bir doğrusal ilişki belirmektedir.

 Indeed, the plot exhibits some "trend," but it also exhibits some "scatter." Therefore, it is a statistical relationship, not a deterministic one.
Gerçekten noktalama şekli bir ‘eğilimi’ göstermekte fakat aynı zamanda bir “dağılmayı”da göstermektedir.  Bu yüzden, bu istatistiksel bir ilişkidir, belirleyici değildir.


Bir Değişkenli Doğrusal İlişki


2. Bir Değişkenli Doğrusal İlişki
(Linear regression with one variable)

Çalışmanın bu kısmında, bir yemek kamyonundan elde edilen kârları tahmin etmek için bir değişkenli doğrusal ilişkiyi uygulayacağız.  Françayz bir restoranın CEO’su olduğunuzu varsayın ve yeni bir outlet açmak için farklı şehirleri değerlendirdiğinizi düşünün.  Françayz zinciri bir çok şehirde kamyonlara sahiptir çoktan ve bu şehirlerden elde edillen kâr ve nüfus verilerine sahipsiniz.

Bir sonra hangi şehiri seçmenize yardım etmek için bu veriyi kullanmak isterdiniz.

                Ex1data1.txt  dosyası doğrusal ilişki problemimiz için veri dosyasın ı içermekte.  Birinci sütun bir şehrin nüfusu ve ikinci sütun o şehirdeki yiyecek kamyonunun kârıdır.  Kamyon için negatif bir değer zararı beliritir.  Ex1.m script’i bu veriyi yüklemeniz için düzenlenmiştir.

 Ex1 örneği ;
 ex1.m , plotData.m ,  gradientDescent.m ,    computeCost.m
script dosyalarından oluşur.

Ex1.m dosyası verilerin okunması ve grafiksel olarak gösterilmesi ile başlar.

%% Initialization
clear ; close all; clc
ARS NOTLARI:
1-Sembol tablosundan desenlerle eşleşen isimleri yok et. (Değişken isimlerini yok et).
2-Şekil pencerelerini kapa.
3-Terminal ekranını sil ve kursorü sol üst köşeye götür.

%% ======================= Part 2: Plotting =======================
fprintf('Plotting Data ...\n')
data = load('ex1data1.txt');
X = data(:, 1); y = data(:, 2);    % X= 97 x 1  y= 97 x 1
m = length(y);                   % number of training examples % 97

% Plot Data
% Note: You have to complete the code in plotData.m
plotData(X, y);

ARS NOTLARI:
1-fprintf('Program paused. Press enter to continue.%s \n',’ ...  ’);
şeklinde format verilmediğine dikkat ediniz.
2-Pause komutunun mesaj yazdırıldıktan sonra çalıştırıldığına
dikkat ediniz.
3- Veriyi incelemek için:
octave:1> data = load('ex1data1.txt');
octave:2> size(data)
ans =

   97    2

octave:3> data(1:5,:)    birinci sütunun ilk beş satır değeri ve herbir satırın kalan
sütun değerleri.
ans =

    6.1101   17.5920
    5.5277    9.1302
    8.5186   13.6620
    7.0032   11.8540
    5.8598    6.8233

4- X = data(:, 1); y = data(:, 2);    % X= 97 x 1  y= 97 x 1
X şehrin nüfusu  10000lerden
Y kâr  10000USD cinsinden

5- m = length(y);                             % number of training examples % 97
Toplam öğrenme örnekleri sayısı

6- plotData(X, y);
Harici fonksiyon olarak tanımlanmış.

7- plotData.m içinde:
figure; % open a new figure window

plot(x, y, 'rx', 'MarkerSize', 10);
ylabel('Profix in $10,000s');
xlabel('Population of City in 10,000s');

8- figure komutu var olan şekil/grafikleri koruyup yeni bir
pencere açar.
9- plot(x, y, 'rx', 'MarkerSize', 10);
X ekseninde X matrisi(şehir nüfusları)
Y ekseninde onunla ilişkili(regression) kârlılık değerleri
‘rx’ grafik noktası kırmızı(red) ve ‘x’ şeklinde, büyüklüğü 10 pixel
Ylabel y ekseninin etiketi, xlabel x ekseninin etiketi.






Monday, 27 August 2018

Neural Networks Simplified - 4

BASİTLEŞTİRİLMİŞ YAPAY SİNİR AĞLARI - 4
Bu eğitim metni Hinton'un iki kursunda kullanılan yapılar
için yapılmış basit örneklere dayanır.  Bu kurslar sırasında
verilen örnekler internet üzerinde yaygın şekilde bulunabilir.

Bu kısımda Hinton'un kullanmış olduğu grafik fonksiyonları
örneklerle anlatılacak.

NEURAL NETWORKS SIMPLIFIED - 4
This is a tutorial based on simple examples made for the
structures used in Hinton's two courses.  The exercises
given during these courses are widely available on the internet.

The graphics functions that Hinton has used will be studied
in this section.

Herhangi bir soru varsa beni aramakta tereddüt etmeyiniz.
Please do not hesitate to contact me if any questions.

Ali R+ SARAL
arsaral((at))yaho(o).com


GRAPHICS FUNCTIONS
*******************************************

x = -10:0.1:10;
plot (x, sin (x))
octave:3> x = -10:0.1:10; plot (x, sin (x),'+');
octave:4> x = -10:0.1:10; plot (x, sin (x),'-');
octave:5> x = -10:0.1:10; plot (x, sin (x),2)
octave:7> x = -10:0.1:10; plot (x, sin (x),'b*')
octave:8> x = -10:0.1:10; plot (x, sin (x),'ro')



scatter
x = randn (100, 1);
y = randn (100, 1);
scatter (x, y, [], sqrt(x.^2 + y.^2));


x =

   0   1   2

octave:81> y
y =

   0   1   2

octave:82> z
z =

   0   0   0
   0   1   2
   0   2   4

x = 0:2; y = x;
z = x’ * y;
contour (x, y, z, 2:3)



octave:9> x=0:4;y=x;
octave:10> z=x'*y;
octave:11> contour(x,y,z,1:5)
octave:12> x
x =

   0   1   2   3   4

octave:13> y
y =

   0   1   2   3   4

octave:14> z
z =

    0    0    0    0    0
    0    1    2    3    4
    0    2    4    6    8
    0    3    6    9   12
    0    4    8   12   16


x=linspace(-2*pi,2*pi);
y=linspace(0,4*pi);
[X,Y] = meshgrid(x,y);
Z=sin(X)+cos(Y);
figure
contour(X,Y,Z)



fplot ("cos", [0, 2*pi]);
fplot ("[cos(x), sin(x)]", [0, 2*pi]);



octave:2> tx=ty=linspace(-8, 8, 4)
tx =

  -8.0000  -2.6667   2.6667   8.0000

octave:3> [xx, yy] = meshgrid(tx, ty)
xx =

  -8.0000  -2.6667   2.6667   8.0000
  -8.0000  -2.6667   2.6667   8.0000
  -8.0000  -2.6667   2.6667   8.0000
  -8.0000  -2.6667   2.6667   8.0000

yy =

  -8.0000  -8.0000  -8.0000  -8.0000
  -2.6667  -2.6667  -2.6667  -2.6667
   2.6667   2.6667   2.6667   2.6667
   8.0000   8.0000   8.0000   8.0000



tx = ty = linspace (-8, 8, 41)’;
[xx, yy] = meshgrid (tx, ty);
r = sqrt (xx .^ 2 + yy .^ 2) + eps;
tz = sin (r) ./ r;
mesh (tx, ty, tz);




[x, y, z] = peaks (20);
scatter3 (x(:), y(:), z(:), [], z(:));



subplot (2, 1, 1);
 fplot (@sin, [-10, 10]);
subplot (2, 1, 2);
fplot (@cos, [-10, 10]);



imagesc(A);

title('Original');




imshow(to_show, [-extreme, extreme]);
       
title('hidden units of the RBM');


ADVANCED FUNCTIONS
************************************************
octave:2> a=[1,2,3;4,5;6]
error: vertical dimensions mismatch (1x3 vs 1x2)
octave:2> a=1:6
a =

   1   2   3   4   5   6

octave:3> reshape(a,2,3)
ans =

   1   3   5
   2   4   6

octave:4> reshape(a,3,2)
ans =

   1   4
   2   5
   3   6

octave:7> b=repmat(c,2)
b =

   1   2   1   2
   3   4   3   4
   1   2   1   2
   3   4   3   4

octave:8> b=repmat(c,2,3)
b =

   1   2   1   2   1   2
   3   4   3   4   3   4
   1   2   1   2   1   2
   3   4   3   4   3   4



FUNCTION CALLS
*******************************************************
[max_value, p] = max(h_of_x, [], 2);

octave:3> [max_value, p] = max(a,[],1)
max_value =

    1    2    3    4    5    6    7    8    9   10

p =

   1   1   1   1   1   1   1   1   1   1

octave:4> a=[1,2,3;4,5,6;7,9,2]
a =

   1   2   3
   4   5   6
   7   9   2

octave:5> [max_value, p] = max(a,[],1)
max_value =

   7   9   6

p =

   3   3   2

octave:6> [max_value, p] = max(a,[],2)
max_value =

   3
   6
   9

p =

   3
   3
   2



octave:28> s="test";
octave:29> function testFuncWithPARM(s)
> fprintf(s)
> end

octave:31> testFuncWithPARM("aaaaaa\n")
aaaaaa


octave:32> i = 0;
octave:33> function testFuncWithIntPARM(i)
> fprintf('i =%d',i)
> end

octave:34> testFuncWithIntPARM(333);
i =333



octave:35> function [out1, out2] = testFuncWithMultiPARM()
> out1=1
> out2=2
> end

octave:36> testFuncWithMultiPARM()
out1 =  1
out2 =  2
ans =  1



extFunc.m  external file
function [out3, out4] = testExtFunc()
out3=99
out4=100
end

octave:42> testExtFunc()
out3 =  99
out4 =  100
ans =  99

Friday, 24 August 2018

Neural Networks Simplified - 3

BASİTLEŞTİRİLMİŞ YAPAY SİNİR AĞLARI - 3
Bu eğitim metni Hinton'un iki kursunda kullanılan yapılar
için yapılmış basit örneklere dayanır.  Bu kurslar sırasında
verilen örnekler internet üzerinde yaygın şekilde bulunabilir.

Bu kısım ile hazır fonksiyonlar bitmiş oluyor. Bundan sonraki kısımlar
kullanıcı tarafından tanımlanan fonksiyonları ele alacak.
Daha sonra ise tek tek Hinton'un örnekleri basite indirgenerek
incelenecek.

NEURAL NETWORKS SIMPLIFIED - 3
This is a tutorial based on simple examples made for the
structures used in Hinton's two courses.  The exercises
given during these courses are widely available on the internet.

Builtin functions is ending with this section.  The next section will
study the user defined functions.  After that Hinton's examples will
be studied with a very simplifying approach.

Herhangi bir soru varsa beni aramakta tereddüt etmeyiniz.
Please do not hesitate to contact me if any questions.

Ali R+ SARAL
arsaral((at))yaho(o).com
BASIC BUILTIN FUNCTIONS
*******************************************
octave:11> any([1,0,0])
ans =  1

octave:15> eye(2,4)
ans =

Diagonal Matrix

   1   0   0   0
   0   1   0   0
octave:12> any (eye (2, 4))
ans =

   1   1   0   0

octave:13> ~any([1,0,0])
ans = 0

octave:14> ~any (eye (2, 4))
ans =

   0   0   1   1



octave:2> isnan ([13, Inf, NA, NaN])
ans =

   0   0   1   1

octave:3> isinf ([13, Inf, NA, NaN])
ans =

   0   1   0   0



octave:6> eval ('error ("This is a bad example");', 'printf ("This error occurred:\n%s\n", lasterr ());');
This error occurred:
This is a bad example

octave:7> eval('error ("HATAAAAAAAAAAAA");')
error: HATAAAAAAAAAAAA

octave:7> eval('error ("ERRORRRRRRRRRRRRRRR");','fprintf("HATAAAAAAA");')
HATAAAAAAA



octave:11> any([1,0,0])
ans =  1

octave:15> eye(2,4)
ans =

Diagonal Matrix

   1   0   0   0
   0   1   0   0
octave:12> any (eye (2, 4))
ans =

   1   1   0   0

octave:13> ~any([1,0,0])
ans = 0

octave:14> ~any (eye (2, 4))
ans =

   0   0   1   1



ctave:19> resets dev environment -->clc;clear;close all



octave:19> checks environment values
octave:19> if ~exist('example_width', 'var') || isempty(example_width)
> end


octave:11> a=1:10
a =

    1    2    3    4    5    6    7    8    9   10

octave:12> avg(a)
ans =  5.5000
octave:13> sum(a)
ans =  55
octave:14> avg(a) == sum(a)/10
ans =  1
octave:15> sum(a)./10
ans =  5.5000

INPUT OUTPUT FUNCTIONS
*********************************************
octave:16> pause

octave:17> fprintf("Press any key to continue");pause;
Press any key to continue



octave:18> % this is a line comment

octave:18> a=1;  %This is a line comment

octave:19> %{
> This is a block comment
> 5}
> %}



fprintf('%s is a name, %d is a number\n',"Ali",58);
Ali is a name, 58 is a number



octave:22> a
a =  1
octave:23> a=1:5
a =

   1   2   3   4   5

octave:24> b=6:10
b =

    6    7    8    9   10

octave:25> disp([a b]);
    1    2    3    4    5    6    7    8    9   10



octave:26> a=1:20
a =

 Columns 1 through 15:

    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15

octave:27> a=[a; a]
a =

 Columns 1 through 15:

    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15
    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15

 Columns 16 through 20:

   16   17   18   19   20
   16   17   18   19   20


octave:30> a=[a; a]
octave:30> a=[a; a]
'less' is not recognized as an internal or external command,
operable program or batch file.

octave:31> Above message is not valid for the diary recording

octave:31> more off
octave:32> a
a =

 Columns 1 through 15:

    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15
    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15
    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15
    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15
    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15
    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15
    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15
    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15

 Columns 16 through 20:

   16   17   18   19   20
   16   17   18   19   20
   16   17   18   19   20
   16   17   18   19   20
   16   17   18   19   20
   16   17   18   19   20
   16   17   18   19   20
   16   17   18   19   20

octave:33> diary off



FILE I/O
*******************************************
octave:22> S=load("dataset1.mat");
octave:23> fieldnames(S)
ans =
{
  [1,1] = neg_examples_nobias
  [2,1] = pos_examples_nobias
  [3,1] = w_init
  [4,1] = w_gen_feas
}

size(S.neg_examples_nobias)
size(S.pos_examples_nobias)

load("dataset1.mat");
size(neg_examples_nobias)
size(pos_examples_nobias)



data = csvread('ex1data2.txt');

% Load File

fid = fopen(filename);

if fid
   
file_contents = fscanf(fid, '%c', inf);
   
fclose(fid);

else
   
file_contents = '';
   
fprintf('Unable to open %s\n', filename);

end


movieList = cell(n, 1);

for i = 1:n
   
% Read line
    line = fgets(fid);
   
% Word Index (can ignore since it will be = i)
   
[idx, movieName] = strtok(line, ' ');
    % Actual Word
   
movieList{i} = strtrim(movieName);

end

fclose(fid);


STRING FUNCTIONS
**********************************************************
octave:4> strtok("aaa bbbb",' ')
ans = aaa


octave:5> strtrim("    aaa bbb  ")
ans = aaa bbb
octave:6> length("12345")
ans =  5


octave:7> strcmp("aaa","aaa")
ans =  1


octave:9> strfind("dfbsdfbadddd","a")
ans =  8


octave:16> email_contents ="[ARS]"
email_contents = [ARS]
octave:17> email_contents = regexprep(email_contents, '<[^<>]+>', ' ');
octave:18> email_contents
email_contents = [ARS]
octave:19> diary off

Thursday, 23 August 2018

NEURAL NETWORKS SIMPLIFIED - 2

BASİTLEŞTİRİLMİŞ YAPAY SİNİR AĞLARI - 2
Bu eğitim metni Hinton'un iki kursunda kullanılan yapılar
için yapılmış basit örneklere dayanır.  Bu kurslar sırasında
verilen örnekler internet üzerinde yaygın şekilde bulunabilir.

Bu kısım daha ileri hazır fonksiyonları içerir.

NEURAL NETWORKS SIMPLIFIED - 2
This is a tutorial based on simple examples made for the
structures used in Hinton's two courses.  The exercises
given during these courses are widely available on the internet.

This section includes more advanced built-in functions.

Herhangi bir soru varsa beni aramakta tereddüt etmeyiniz.
Please do not hesitate to contact me if any questions.

Ali R+ SARAL
arsaral((at))yaho(o).com

MATRIX UTILITY FUNCTIONS
*******************************************************

octave:2> a=[1,2,3;4,5,6]
a =

   1   2   3
   4   5   6

octave:3> log(a)
ans =

   0.00000   0.69315   1.09861
   1.38629   1.60944   1.79176

octave:4> a=[-1,-2,3;4,-5,-6]
a =

  -1  -2   3
   4  -5  -6

octave:5> abs(a)
ans =

   1   2   3
   4   5   6

octave:6> exp(a)
ans =

  3.6788e-001  1.3534e-001  2.0086e+001
  5.4598e+001  6.7379e-003  2.4788e-003

octave:7> sum(a)
ans =

   3  -7  -3

octave:8> a
a =

  -1  -2   3
   4  -5  -6

octave:9> sumsq(a)
ans =

   17   29   45

octave:10> a=[4,9]
a =

   4   9

octave:11> sqrt(a)
ans =

   2   3

octave:12> mod(a,2)
ans =

   0   1

octave:13> mod(3,2)
ans =  1

octave:14> floor ([-2.7, 2.7])
ans =

  -3   2

octave:15> floor(3.4)
ans =  3
octave:16> ceil(3.4)
ans =  4
octave:17> ceil([-2.7,2.7])
ans =

  -2   3

octave:18> realmax()
ans =  1.7977e+308
octave:19> a=[1,2,3;4,5,6;7,8,9]
a =

   1   2   3
   4   5   6
   7   8   9

octave:20> bsxfun(@minus, a,2)
ans =

  -1   0   1
   2   3   4
   5   6   7

octave:21> a=[3,1,5;3,4,2;7,3,5]
a =

   3   1   5
   3   4   2
   7   3   5

octave:22> sort(a)
ans =

   3   1   2
   3   3   5
   7   4   5

octave:23> a
a =

   3   1   5
   3   4   2
   7   3   5

octave:24> sort ([1, 2; 2, 3; 3, 1])
ans =

   1   1
   2   2
   3   3

octave:25> [s, i] = sort ([1, 2; 2, 3; 3, 1])
s =

   1   1
   2   2
   3   3

i =

   1   3
   2   1
   3   2

octave:26> [s, i] = sort ([1, 2; 2, 3; 3, 1], 'descend');
octave:27> s
s =

   3   3
   2   2
   1   1

octave:28> i
i =

   3   2
   2   1
   1   3

octave:29> a
a =

   3   1   5
   3   4   2
   7   3   5

octave:30> mean(a)
ans =

   4.3333   2.6667   4.0000

octave:31> find(a==2)
ans =  8
octave:32> a(8)
ans =  2
octave:33> a=[1,1;1,1]
a =

   1   1
   1   1

octave:34> inv(a)
warning: inverse: matrix singular to machine precision, rcond = 0
ans =

   Inf   Inf
   Inf   Inf

octave:35> pinv(a)
ans =

   0.25000   0.25000
   0.25000   0.25000

octave:36> a=[1,2,3;4,5,6]
a =

   1   2   3
   4   5   6

octave:37> pinv(a)
ans =

  -0.94444   0.44444
  -0.11111   0.11111
   0.72222  -0.22222


octave:38> a=[1,2,3;4,5,6;7,8,9]
a =

   1   2   3
   4   5   6
   7   8   9

octave:39> X=[ones(3,1) a]
X =

   1   1   2   3
   1   4   5   6
   1   7   8   9

octave:40> b=[1;2;3]
b =

   1
   2
   3

octave:41> a(2,:) = b
a =

   1   2   3
   1   2   3
   7   8   9

octave:42> a
a =

   1   2   3
   1   2   3
   7   8   9

octave:43> a(2,:) = b'
a =

   1   2   3
   1   2   3
   7   8   9


octave:44> Y=[a(:) ; b(:)]
Y =

   1
   1
   7
   2
   2
   8
   3
   3
   9
   1
   2
   3

octave:45> find(a>3)
ans =

   3
   6
   9

octave:46> a
a =

   1   2   3
   1   2   3
   7   8   9

octave:47> ndx=find(a>3)
ndx =

   3
   6
   9

octave:48> for i=1:length(ndx)
> a(ndx(i)) = 1;
> end
octave:49> a
a =

   1   2   3
   1   2   3
   1   1   1

octave:50>
octave:50> a=[1.2,3.4,5.0]
a =

   1.2000   3.4000   5.0000

octave:51> round(a)
ans =

   1   3   5

octave:52> randperm(3,4)
ans =

   2   3   1
   1   2   3
   1   3   2
   2   1   3

octave:53> randperm(3)
ans =

   2   1   3

octave:54> a=cell(2,4)
a =
{
  [1,1] = [](0x0)
  [2,1] = [](0x0)
  [1,2] = [](0x0)
  [2,2] = [](0x0)
  [1,3] = [](0x0)
  [2,3] = [](0x0)
  [1,4] = [](0x0)
  [2,4] = [](0x0)
}
octave:55> a(1,1)=5
a =
{
  [1,1] =  5
  [2,1] = [](0x0)
  [1,2] = [](0x0)
  [2,2] = [](0x0)
  [1,3] = [](0x0)
  [2,3] = [](0x0)
  [1,4] = [](0x0)
  [2,4] = [](0x0)
}


octave:59> a=["a","b"]
a = ab
octave:60> a(1,1)
ans = a
octave:61> a(1,2)
ans = b
octave:62> a
a = ab
octave:63> a=cell(2)
a =
{
  [1,1] = [](0x0)
  [2,1] = [](0x0)
  [1,2] = [](0x0)
  [2,2] = [](0x0)
}
octave:64> a(1,1)="a"
a =
{
  [1,1] = a
  [2,1] = [](0x0)
  [1,2] = [](0x0)
  [2,2] = [](0x0)
}
octave:65> a(2,1)="b"
a =
{
  [1,1] = a
  [2,1] = b
  [1,2] = [](0x0)
  [2,2] = [](0x0)
}


diary off

Tuesday, 21 August 2018

Neural Networks Simplified - 1

BASİTLEŞTİRİLMİŞ YAPAY SİNİR AĞLARI - 1
Bu eğitim metni Hinton'un iki kursunda kullanılan yapılar
için yapılmış basit örneklere dayanır.  Bu kurslar sırasında
verilen örnekler internet üzerinde yaygın şekilde bulunabilir.

NEURAL NETWORKS SIMPLIFIED - 1
This is a tutorial based on simple examples made for the
structures used in Hinton's two courses.  The exercises
given during these courses are widely available on the internet.

Herhangi bir soru varsa beni aramakta tereddüt etmeyiniz.
Please do not hesitate to contact me if any questions.

Ali R+ SARAL
arsaral((at))yaho(o).com

MATRIX DEFINITIONS
***************************************

a is a 2 x 3 matrix.  a has 2 rows and 3 columns.
a 2 x 3 bir matristir. a'nın iki satırı ve 3 sütunu vardır.

octave:65> a=[1,2,3;4,5,6]
a =

   1   2   3
   4   5   6

octave:66> size(a)
ans =

   2   3
An other matrix definition statement is: a(beg : end)
Bir başka matris tanımlama komutu: a(baş : son)
octave:73> a=(-1:3)
a =

  -1   0   1   2   3

An other matrix definition statement is: a(beg :increment : end)
Bir başka matris tanımlama komutu: a(baş : arttırım adımı : son)
octave:75> a=(-1:0.5:2)
a =

   -1.0000   -0.5000    0.0000    0.5000    1.0000    1.5000    2.0000

An other matrix definition statement is: linspace(beg : step count : end)
Bir başka matris tanımlama komutu: linspace(baş : adım sayısı : son)
octave:77> a=linspace(1,0.5,3)
a =

   1.00000   0.75000   0.50000

octave:78> a=linspace(1,3,3)
a =

   1   2   3

octave:79> a=linspace(1,3,4)
a =

   1.0000   1.6667   2.3333   3.0000


MATRIX ELEMENT ADDRESSING
MATRİS ELEMAN ADRESLEME
***************************************

octave:84> a=[1,2,3;4,5,6]
a =

   1   2   3
   4   5   6

octave:85> a(1)
ans =  1
octave:86> a(1:4)
ans =

   1   4   2   5

octave:87> a(1:6)
ans =

   1   4   2   5   3   6

octave:88> a(1:2,1)
ans =

   1
   4

octave:89> a(1:2,3)
ans =

   3
   6

octave:90> a(1:2,[1 3])
ans =

   1   3
   4   6

octave:91> a(1:2,1:3)
ans =

   1   2   3
   4   5   6

octave:92> a(1:2,:)
ans =

   1   2   3
   4   5   6

octave:93> a(:,1:2)
ans =

   1   2
   4   5

octave:94> a(1,1:3)
ans =

   1   2   3

octave:95> a(:,:)
ans =

   1   2   3
   4   5   6

octave:104> a=[1,2,3;4,5,6;7,8,9]
a =

   1   2   3
   4   5   6
   7   8   9


octave:106> b=[1,2]
b =

   1   2

octave:107> a(b,:)
ans =

   1   2   3
   4   5   6

octave:108> a(1,:)
ans =

   1   2   3


BASIC MATRIX FUNCTIONS
***************************************

octave:2> ndims([1,2;3,4])
ans =  2

octave:10> ones(2,3)
ans =

   1   1   1
   1   1   1

octave:11> zeros(1,2)
ans =

   0   0

octave:12> eye(1,3)
ans =

Diagonal Matrix

   1   0   0

octave:13> eye(3)
ans =

Diagonal Matrix

   1   0   0
   0   1   0
   0   0   1

octave:14> a = 13; a(ones (1, 4))
ans =

   13   13   13   13

octave:17> rand(3)
ans =

   0.61503   0.73559   0.16378
   0.11622   0.89969   0.96928
   0.16057   0.14347   0.84992

octave:14> a = 13;
octave:18> size(a)
ans =

   1   1

octave:19> a=[1,2;3,4;5,6]
a =

   1   2
   3   4
   5   6

octave:20> size(a)
ans =

   3   2

octave:21> b=1
b =  1
octave:22> size(b)
ans =

   1   1


octave:2> zeros(1)
ans = 0
octave:3> zeros(2,2)
ans =

   0   0
   0   0

octave:4> zeros(2,3)
ans =

   0   0   0
   0   0   0

octave:5> a=[1,2;3,4;5,6]
a =

   1   2
   3   4
   5   6

octave:6> zeros(size(a))
ans =

   0   0
   0   0
   0   0

octave:7> size(a)
ans =

   3   2

octave:8> eye(0)
ans = [](0x0)

octave:9> eye(1)
ans =  1

octave:10> eye(2)
ans =

Diagonal Matrix

   1   0
   0   1

octave:11> eye(2,3)
ans =

Diagonal Matrix

   1   0   0
   0   1   0

octave:12> ones(0)
ans = [](0x0)

octave:13> ones(1)
ans =  1

octave:14> ones(2)
ans =

   1   1
   1   1

octave:15> ones(2,3)
ans =

   1   1   1
   1   1   1

octave:16> rand(0)
ans = [](0x0)

octave:17> rand(1)
ans =  0.76538

octave:18> rand(1)
ans =  0.74158

octave:19> rand(2)
ans =

   0.62458   0.30045
   0.48308   0.36512

octave:62> rand(2)
ans =

   0.148336   0.481660
   0.082268   0.182176

octave:20> rand(2,3)
ans =

   0.056270   0.180314   0.794059
   0.905070   0.366595   0.562126

octave:21> a=[1,2;3,4]
a =

   1   2
   3   4

octave:22> size(a)
ans =

   2   2

octave:23> b=[1,2,3;4,5,6]
b =

   1   2   3
   4   5   6

octave:24> size(b)
ans =

   2   3

octave:25> length(b)
ans =  3

octave:26> length(a)
ans =  2

octave:27> c=[1,2,3,4,5]
c =

   1   2   3   4   5

octave:28> length(c)
ans =  5

octave:29> max(c)
ans =  5

octave:30> max(b)
ans =

   4   5   6

octave:31> max(a)
ans =

   3   4

octave:32> min(c)
ans =  1

octave:33> min(b)
ans =

   1   2   3

octave:34> min(a)
ans =

   1   2

octave:35> d=[2,3,1,5,6,4]
d =

   2   3   1   5   6   4

octave:36> min(d)
ans =  1

octave:37> max(d)
ans =  6

octave:38> d=[2,3,1,5,6,4;1,2,3,4,5,6]
d =

   2   3   1   5   6   4
   1   2   3   4   5   6

octave:39> min(d)
ans =

   1   2   1   4   5   4

octave:40> max(d)
ans =

   2   3   3   5   6   6

octave:41> numel(d)
ans =  12

octave:42> numel(c)
ans =  5

octave:43> numel(b)
ans =  6

octave:44> numel(a)
ans =  4

norm (A, p, opt)
Compute the p-norm of the matrix A.
If the second argument is missing, p = 2 is assumed.
If A is a matrix (or sparse matrix):
p = 1 1-norm, the largest column sum of the absolute values of A.
p = 2 Largest singular value of A.

octave:45> norm(a)
ans =  5.4650     <===========

octave:46> a
a =

   1   2
   3   4

octave:49> [U,S,V]=svd(a) 
Compute the singular value decomposition of A
A'nın tekil değer ayrıştırımını hesaplayınız.

U =

  -0.40455  -0.91451
  -0.91451   0.40455

S =

Diagonal Matrix

   5.46499         0   <===========
         0   0.36597

V =

  -0.57605   0.81742
  -0.81742  -0.57605

octave:50> b
b =

   1   2   3
   4   5   6

octave:51> [U,S,V]=svd(b)
U =

  -0.38632  -0.92237
  -0.92237   0.38632

S =

Diagonal Matrix

   9.50803         0         0   <===========
         0   0.77287         0

V =

  -0.42867   0.80596   0.40825
  -0.56631   0.11238  -0.81650
  -0.70395  -0.58120   0.40825

octave:52> norm(b)
ans =  9.5080    <===========

octave:53> c
c =

   1   2   3   4   5

octave:54> [U,S,V]=svd(c)
U =  1
S =

Diagonal Matrix

   7.4162        0        0        0        0   <===========

V =

   0.134840  -0.269680  -0.404520  -0.539360  -0.674200
   0.269680   0.935914  -0.096129  -0.128172  -0.160215
   0.404520  -0.096129   0.855807  -0.192258  -0.240322
   0.539360  -0.128172  -0.192258   0.743656  -0.320430
   0.674200  -0.160215  -0.240322  -0.320430   0.599463

octave:55> norm(c)
ans =  7.4162           <===========