octave

How to implement tensor product for arbitrary order tensors in octave?

南楼画角 提交于 2019-12-11 07:09:10
问题 I dont have access to matlab, so I am trying some things with octave . How would you efficiently implement the tensor product described in the following formula? My approach for arbitrary order tensors a and b is the following % Tensor product function out = tp(a,b) if isvector(a) da = prod(size(a)); else da = size(a); endif if isvector(b) db = prod(size(b)); else db = size(b); endif out = reshape(a(:)*(b(:)'),[da,db]); endfunction The if statements are only there in order to catch the case

Running portions of a loop in parallel with Octave?

故事扮演 提交于 2019-12-11 06:48:49
问题 I have the following code that I need to run over a matrix with over 20000 rows. It takes several minutes to run and the datenum and str2double functions appear to be the bottlenecks. Since no calculation depends on previous ones is there a way to break the loop into multiple parts and have them execute in parallel? Any advice on optimising this code would be appreciated. for i=1:length(DJI) DJI2(i,1)=datenum(char(DJI(i,2)),'yyyy-mm-dd'); for j=3:7 DJI2(i,j-1)=str2double(char(DJI(i,j))); end

Vectorized Implementation of Softmax Regression

泪湿孤枕 提交于 2019-12-11 06:46:32
问题 I’m implementing softmax regression in Octave. Currently I’m using a non-vectorized implementation using following cost function and derivatives. Source: Softmax Regression Now I want to implement vectorized version of it in Octave. It seems like bit hard for me to write vectorized versions for these equations. Can somebody help me to implement this ? Thanks Upul 回答1: This is very similar to an exercise in Andrew Ng's deep learning class, they give some hints http://ufldl.stanford.edu/wiki

Searching for a word in a grid

浪子不回头ぞ 提交于 2019-12-11 05:48:21
问题 I'm trying to write a function that takes a square grid of letters and given a word to find from a list of words, it searches for it horizontally, vertically or diagonally (also looking backwards in each case). I've tried writing this function in various ways with no success so was wondering if my general algorithm sounded ok and implementable. Return co-ordinates for everywhere the first letter of the word occurs so something like [row,col] = find(grid==words(2)) with words being the list of

Reading frame after converting Matlab pdollar toolbox code to Octave

眉间皱痕 提交于 2019-12-11 05:38:26
问题 I want to read a video using pdollar toolbox. I have few video files upon whom I am trying to apply the acfDetect classier. However, I don't get the correct output. On checking, I found that the data of the frame (the matrix) do not match, for Matlab and Octave. The question will be clear with the attached pics. I tried to print the value of the frame and this is what I get: Matlab output: Octave output: As a hit an trial, I saw that multiplying Octave values by 255 (RGB max) gives me an

“Couldn't resolve hostname” while installing package in Octave

六月ゝ 毕业季﹏ 提交于 2019-12-11 05:38:16
问题 I have tried installing a package in Octave using this command: pkg install signal-1.4.0.taz.gz but I received the following error: error: pkg: failed to read package 'signal-1.4.0.taz.gz': Couldn't resolve host name error: called from pkg at line 429 column 17 Does somebody know what that means? 回答1: You have mis-spelled the name of the package's tarball. It is likely signal-1.4.0.tar.gz rather than signal-1.4.0.taz.gz pkg install signal-1.4.0.tar.gz Essentially what is happening, is that

Write to a matrix in .oct file without looping?

喜你入骨 提交于 2019-12-11 05:29:46
问题 In an Octave .oct file it is possible to extract a submatrix thus: B = A.extract(a-1,c-1,b-1,d-1) ; the equivalent of B = A(a:b,c:d) in Octave code, but is it possible to write to a subset of a matrix in a similar manner, A(a-1,c-1,b-1,d-1) = B ; // some other smaller matrix or would I have to loop over the relevant rows/columns and write element by element? 回答1: Assuming A is of class Array , you can use one of the following methods (see the documentation): Array<T> & insert (const Array<T>

Looping through a 3D array to find the mean and standard deviation

坚强是说给别人听的谎言 提交于 2019-12-11 05:28:37
问题 Ok so I have an array <134x106x108>. What I'm trying to do is loop through this array and store the average/standard deviation into another array. So basically there will be 134 <106x108 doubles> that will be in this meanArray and sdArray. %dayv=<134x106x108> sdArray=zeros(1,106,108); meanArray=zeros(1,106,108); for i=1:size(dayv,1) %store means/standard deviation into an array meanArray(i,:,:) = squeeze(mean(dayv(i,:,:))); sdArray(i,:,:) = squeeze(std(dayv(i,:,:))); end 回答1: If you want each

How to customize contour line labels?

痴心易碎 提交于 2019-12-11 05:27:05
问题 I would like to visualize a function of two variables in a contour plot using Octave, and to put customized line labels on it. Building on the Octave documentation, I wrote: clf; colormap ("default"); [x, y, z] = peaks (); subplot(2,1,1); contour (x, y, z,'showtext', 'on'); title ({"contour() plot, showtext on"; "Z = peaks()"}); subplot(2,1,2); [ctr, h] = contour (x, y, z); cll = clabel(ctr, h, 'backgroundcolor',[1 1 1]); title ({"contour() plot, using clabel()"; "Z = peaks()"}); Which

Matlab regular expressions capture groups with named tokens

我们两清 提交于 2019-12-11 05:23:16
问题 I am trying to read a few text lines from a file in matlab. Using the regexp function to extract some named tokens. While everything works quite nice in octave I cannot get the same expression to work in Matlab. There are different kinds of lines i want to process, like: line1 = 'attr enabled True'; line2 = 'attr width 1.2'; line3 = 'attr size 8Byte'; The regular expression I have come up with looks like: pattern = '^attr +(?<name>\S+) +(?:(?<number>[+-]?\d+(?:\.\d+)?)(?<unit>[a-z,A-z]*)?|(?