Reading MNIST Handwritten digit data in system Verilog - deep-learning

My goal is to read data from MNIST file using system Verilog and perform a dot product between two image shape numbers by reading these files in a test vector arrays. And display that result. noting that, I have taken only the first 200X785 mnist file data and converted to a txt file so I could use $readmemb in system verilog even though the data inside these files are in gray scale 0-255 can you guys help?
`begin_keywords "1800-2012" //Use keyword list from SystemVerilog-2012.
module read_write ( // This is DUT. It specifies input signals to drive the DUT.
// input from MNIST files
input logic [784:0] A1, A2,output logic [784:0] product_0_1,);
timeunit 1ns/1ns; // Simulation time unit of 1 ns, with precision of 1 ns.
// at start of test load testvectors
initial
begin
$readmemb ("D:/New Folder/MNIST200.txt",testvectors);//the mnist is stored in a test
vector file "MNIST200.txt".
//using a for loop to read in each of the values within the test vector array
for (int i=0;i<785; i=i+1)
begin
$display("%b", testvectors[i]);
end
$finish;
end
always_comb
begin
//Sum of product
// to identify the rectified linear unit. activation function
product_0_1 <= sum (A1 * A2);
end
endmodule:read_write;
`end_keywords

Related

how can I implement a function to load data into a design matrix and an output vector in octave

I have a .txt file with dimensions 100x4 but i want to generalise and make an initial matrix with m x n+1 dimension as the code should work fine with any data file. m is the number of training examples and n is the number of training features and the last column is the output vector.
function [X,y]= loadData(filename)
data=load(filename);
X=load(filename);
y=load(filename);
m=rows(filename);
n=size(filename);
end
expected value of elements in the matrix do not match the found value.
what is the mistake?
First of all you are loading 3 times the same things, so at the end data, X, and y contain exactly the same things.
Then you are passing filename -that is a string- to rows() and size(), so do not expect getting the sizes of some arrays: these functions won't open any file, they just operate on the string in this case. In octave a string is considered as a 1xl matric, l being the length of the string.

convert large stars object to sf object

My ultimate goal is to convert landcover raster (.tif) objects to an sf object representing the raster's grid and the original values of each cell within each geometry. I have been able to do this for smaller rasters doing the following:
library(sf)
library(stars)
# import raster using stars
landcover_stars <- read_stars(my_raster.tif)
# convert to sf object using st_as_sf
landcover_grid_sf <- st_as_sf(landcover_stars)
In larger rasters (e.g. my largest raster is currently 11482x12607 cells), however, the read_stars() function imports the raster as a "stars proxy", which is a step taken to handle large raster datasets by the package. While stars proxy objects are not accepted by the st_as_sf function, it is possible to set "proxy = FALSE" in the function. If I do this in my largest dataset, however, running st_as_sf(landcover_stars) with the resulting object will crash my laptop {16 GB RAM, i7 2.70GHz processor}.
Is there a way I can proceed to ease the load on my machine when converting very large star objects to sf?
In addition - could it be that it is actually the newly generated sf object what is depleting my machine?
Here is a dummy raster in case youd like to test it, with integer values randomly generated ranging from 1 to 10:
raster(nrows=12000, ncols=12000, xmn=0, xmx=10, vals = floor(runif(12000*12000, min=0, max=11)))

GnuPlot :: Plotting 3D recorded in an unconventional format

I would like to prepare a script file to draw a 3D plot of some kinetic spectroscopy results. In the experiment the absorption spectrum of a solution is measured sequentially at increasing times from t0 to tf with a constant increase in time Δt.
The plot will show the variation of absorbamce (Z) with wavelength and time.
The data are recorded using a UV-VIS spectrometer and saved as a CSV text file.
The file contains a table in which the first column are the wavelengths of the spectra. Afterwards, a column is added for each the measured spectra, and a number of columns depends on the total time and the time interval between measuerments. The time for each spectra appears in the headers line.
I wonder if the data can be plotted directly witha minimum of preformatting and without the need to rewrite the data in a more estandar XYZ format.
The structure of the data file is something like this
Title; espectroscopia UV-Vis
Comment;
Date; 23/10/2018 16:41:12
Operator; laboratorios
System Name; Undefined
Wavelength (nm); 0 Min; 0,1 Min; 0,2 Min; 0,3 Min; ... 28,5 Min
400,5551; 1,491613E-03; 1,810312E-03; 2,01891E-03; ... 4,755786E-03
... ... ... ... ... ...
799,2119; -5,509266E-04; 3,26314E-04; -4,319865E-04; ... -5,087912E-04
(EOF)
A copy of a sample data is included in this file kinetic_spectroscopy.csv.
Thanks.
Your data is in an acceptable form for gnuplot, but persuading the program to plot this as one line per wavelength rather than a gridded surface is more difficult. First let's establish that the file can be read and plotted. The following commands should read in the x/y coordinates (x = first row, y = first column) and the z values to construct a surface.
DATA = 'espectros cinetica.csv'
set datafile separator ';' # csv file with semicolon
# Your data uses , as a decimal point.
set decimal locale # The program can handle this if your locale is correct.
show decimal # confirm this by inspecting the output from "show".
set title DATA
set ylabel "Wavelength"
set xlabel "Time (min)"
set xyplane 0
set style data lines
splot DATA matrix nonuniform using 1:2:3 lc palette
This actually looks OK with your data. For a smaller number of scans it is probably not what you would want. In order to plot separate lines, one per scan, we could break this up into a sequence of line plots rather than a single surface plot:
DATA = 'espectros cinetica.csv'
set datafile separator ";"
set decimal locale
unset key
set title DATA
set style data lines
set ylabel "Wavelength"
set xlabel "Time (min)"
set xtics offset 0,-1 # move labels away from axis
splot for [row=0:*] DATA matrix nonuniform every :::row::row using 1:2:3
This is what I get for the first 100 rows of your data file. The row data is colored sequentially by gnuplot linetypes. Other coloring schemes are possible.

How to plot a transfer function from a Cauer network

The picture below shows a Cauer network, which is a continued fraction network.
I have built the 3rd olrder transfer function 3rd Octave like this:
function uebertragung=G(R1,Tau1,R2,Tau2,R3,Tau3)
s= tf("s");
C1= Tau1/R1;
C2= Tau2/R2;
C3= Tau3/R3;
# --- Uebertragungsfunktion 3.Ordnung --- #
uebertragung= 1/((s*R1*C1)^3+5*(s*R2*C2)^2+6*s*R3*C3+1);
endfunction
R1,R2,R3,C1,C2,C3 are the 6 parameters my characteristic curve depends on.
I need to put this parameters into the tranfser function, get a result and plot the characteristic curve from the data.
The characteristic curve shows thermal impedance vs time. Like these 2 curves from an igbt data sheet.
My problem is I don't know how to handle transfer functions properly. I need data to plot the characteristic curve but I don't know how to generate them out of the transfer function.
Any tips are welcome. Do I have to make Laplace transformation?
If you need further Information ask me and I try to provide them all.
From the data sheet, the equation they are using for their transient thermal impedance graph is the Foster chain step function response:
Z(t) = sum (R_i * (1-exp(-t/tau_i))) = sum (R_i * (1-exp(-t/(R_i*C_i))))
I verified that the stage R's and C's in the table by the graph will produce the plot you shared with that function.
The method for producing a step function response of an s-domain (Laplace domain) impedance function (Z) is to take the inverse Laplace transform of the product of the transfer function and 1/s (the Laplace domain form of a constant value step function). With the Foster model impedance function:
Z(s) = sum (R_i/(1+R_i*C_i*s))
that will produce the equation above.
Using the transfer function in Octave, you can use the Control package function step to calculate the transient response for you rather than performing the inverse Laplace transform yourself. So once you have Z(s), step(Z) will produce or plot the transient response. See help step for details. You can then adjust the plot (switch to log scale, set axes limits, etc) to look like one of the spec sheet plots.
Now, you want to do the same thing with a Cauer network model. It is important to realize that the R's and C's will not be the same for the two models. The Foster network is a decoupled model that has each primary complex pole isolated by layout, but the R's and C's are actually convolutions of the physical thermal resistances and capacitances in the real package. On the contrary, the Cauer model has R's and C's that match the physical package layers, and the poles in the s-domain transfer function will be complex products of the multiple layers.
So, however you are obtaining your R's and C's for the Cauer model, you can't just use the same values they have in their Foster model parameter table. They can be calculated from physical layer and material properties, however, assuming you have that information. Once you do have useful values, the procedure for going from Z(s) to the transient impedance function is the same for either network, and they should produce the same result.
As an example, the following procedure should work in both Octave and Matlab to plot the Thermal impedance curve from the spec sheet data using the Foster Z(s) model as a starting point. For the Cauer model, just use a different Z(s) function.
(Note that Octave has some issues in the step function that insert t = 0 entries into the time series output, even when they aren't specified, which can cause some errors when trying to plot on a log scale. so this example puts in a t=0 node then ignores it. wanted to explain so that line didn't seem confusing).
s = tf('s')
R1 = 8.5e-3; R2 = 2e-3;
tau1 = 151e-3; tau2 = 5.84e-3;
C1 = tau1/R1; C2 = tau2/R2;
input_imped = R1/(1+R1*C1*s)+R2/(1+R2*C2*s)
times = linspace(0, 10, 100000);
[Zvals,output_times] = step(input_imped, times);
loglog(output_times(2:end), Zvals(2:end));
xlim([.001 10]); ylim([0.0001, .1]);
grid;
xlabel('t [s]');
ylabel('Z_t_h_(_j_-_c_) [K/W] IGBT');
text(1,0.013 ,'Z_t_h_(_j_-_c_) IGBT');

Floating point Data generator

Is there a program or source code for data generation?
I want a data generator for Java. (Language does not matter, if I can get the result file)
I want a correlated data, anti-correlated data, independent data.
I want a data generator program that has
input : min, max, data-distribution (ex., independent, anti-correlated, correlated, Gaussian, Poisson ... ), dimension, # of points (n)
output : n points that follows given data-distribution.
Thank you :)
You can change the interval of the generated numbers with some simple math:
Random r=new Random();
floatx=(r.nextFloat()%(max+min))-min;
The java random class also has an option to return gaussian distributed values.