Wrong data array when reading a text file in Octave - octave
I want to read a text file, which has two columns and that looks as follows.
-0,090 26,295
-0,342 26,294
-0,594 26,294
-0,846 26,295
-1,098 26,294
-1,368 26,296
-1,620 26,296
-1,872 26,296
I'm using the following code to read it and to create the data array.
filename = 'C:\Users\file location\test.txt';
delimiter = '\t';
formatSpec = '%s%s%[^\n\r]';
fileID = fopen(filename,'rt');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'ReturnOnError', false, 'EndOfLine', '\r\n');
fclose(fileID);
What I get is an array like this.
dataArray =
{
[1,1] =
{
[1,1] = -0,090
[2,1] = -0,594
[3,1] = -1,098
[4,1] = -1,620
[5,1] =
}
[1,2] =
{
[1,1] = 26,295
[2,1] = 26,294
[3,1] = 26,294
[4,1] = 26,296
[5,1] =
}
[1,3] =
{
[1,1] = -0,342 26,294
[2,1] = -0,846 26,295
[3,1] = -1,368 26,296
[4,1] = -1,872 26,296
[5,1] =
}
}
So apparently Octave takes only every second row of my original columns to create my array and combines the skipped values to a third column.
What I actually expect is an array like this.
dataArray =
{
[1,1] =
{
[1,1] = -0,090
[2,1] = -0,342
[3,1] = -0,594
[4,1] = -0,846
[5,1] = -1,098
[6,1] = -1,368
[7,1] = -1,620
[8,1] = -1,872
}
[1,2] =
{
[1,1] = 26,295
[2,1] = 26,294
[3,1] = 26,294
[4,1] = 26,295
[5,1] = 26,294
[6,1] = 26,296
[7,1] = 26,296
[8,1] = 26,296
}
}
I assume it's a problem with formatSpec. Is it somehow possible to adjust my code so that I get my expected array?
The main issue here is that commas are used instead of dots in your file.
My advice would be to forget about elaborate textscanning, and simply preprocess your files instead, to replace the offending commas with dots. This can be done easily on a linux terminal, however it's easy enough to do in octave as well if you prefer, e.g.
% Read in file as string
Data_str = fileread('test.txt');
% Correct commas to dots
CorrectedData_str = strrep( Data_str, ',' , '.' );
% Write data back to a file (I'm surprised there's no equivalent "filewrite" ...)
f = fopen( 'corrected_test.txt', 'w' );
fprintf(f, CorrectedData_str);
fclose(f);
Once you have preprocessed all your data, importing is then as simple as:
MyData = importdata('corrected_test.txt');
Related
Get array item by 1-indexed value in another field
The Firefox file sessionstore-backups/recovery.jsonlz4 contains information about the current Firefox windows in (compressed) JSON format. This is a simplified format representative of that file: { "index": 2, "entries": [ { "title": "Foo bar 0", "url": "https://example.com/bar" }, { "title": "Foo bar 1", "url": "https://example.com/bar" }, { "title": "Foo bar 2", "url": "https://example.com/bar" } ] } The index field represents the currently-displayed history item per tab. Being 1-indexed, in the example above it represents the "Foo bar 1" entry. How can I use that value in jq to get that tab? For testing on your own system, the following bash line will get you to this point on most modern Linux systems: lz4jsoncat ~/.mozilla/firefox/t6e99qbe.default-release/sessionstore-backups/recovery.jsonlz4 | jq '.windows[0].tabs' | jq 'sort_by(.lastAccessed)[-1]' This returns the most recent tab, but with all history items in the entries array. As the user could have navigated back in the history, we need the index value to determine which entry to return. Piped through gron, it looks like this: json = {}; json.attributes = {}; json.entries = []; json.entries[0] = {}; json.entries[0].ID = 504; json.entries[0].cacheKey = 0; json.entries[0].docIdentifier = 586; json.entries[0].docshellUUID = "{b6c1e18a-d0f5-4ba2-996e-ddd9fc28322a}"; json.entries[0].hasUserInteraction = true; json.entries[0].persist = true; json.entries[0].principalToInherit_base64 = "eyIxIjp7IjAiOiJtb3otZXh0ZW5zaW9uOi8vOTAzYWU2NDgtMzRlNi00NGQ3LTg0NjYtYzgxMWQyMTg2YjBkLyJ9fQ=="; json.entries[0].resultPrincipalURI = null; json.entries[0].title = "Tridactyl Top Tips & New Tab Page"; json.entries[0].triggeringPrincipal_base64 = "eyIxIjp7IjAiOiJtb3otZXh0ZW5zaW9uOi8vOTAzYWU2NDgtMzRlNi00NGQ3LTg0NjYtYzgxMWQyMTg2YjBkLyJ9fQ=="; json.entries[0].url = "moz-extension://7ba85bcd-8d63-4e74-a723-e627a31d6274/static/newtab.html"; json.entries[1] = {}; json.entries[1].ID = 506; json.entries[1].cacheKey = 0; json.entries[1].docIdentifier = 588; json.entries[1].docshellUUID = "{b6c1e18a-d0f5-4ba2-996e-ddd9fc28322a}"; json.entries[1].hasUserInteraction = true; json.entries[1].persist = true; json.entries[1].referrerInfo = "BBoSnxDOS9qmDeAnom1e0AAAAAAAAAAAwAAAAAAAAEYAAAAAAAEBAAAAAAEA"; json.entries[1].resultPrincipalURI = null; json.entries[1].title = "Stack Overflow - Where Developers Learn, Share, & Build Careers"; json.entries[1].triggeringPrincipal_base64 = "eyIzIjp7fX0="; json.entries[1].url = "https://stackoverflow.com/"; json.entries[2] = {}; json.entries[2].ID = 508; json.entries[2].cacheKey = 0; json.entries[2].csp = "CdntGuXUQAS/4CfOuSPZrAAAAAAAAAAAwAAAAAAAAEYB3pRy0IA0EdOTmQAQS6D9QJIHOlRteE8wkTq4cYEyCMYAAAAC/////wAAAbsBAAAAGmh0dHBzOi8vc3RhY2tvdmVyZmxvdy5jb20vAAAAAAAAAAUAAAAIAAAAEQAAAAj/////AAAACP////8AAAAIAAAAEQAAABkAAAABAAAAGQAAAAEAAAAZAAAAAQAAABoAAAAAAAAAGv////8AAAAA/////wAAABn/////AAAAGf////8BAAAAAAAAAAAAKHsiMSI6eyIwIjoiaHR0cHM6Ly9zdGFja292ZXJmbG93LmNvbS8ifX0AAAABAAAASwB1AHAAZwByAGEAZABlAC0AaQBuAHMAZQBjAHUAcgBlAC0AcgBlAHEAdQBlAHMAdABzADsAIABmAHIAYQBtAGUALQBhAG4AYwBlAHMAdABvAHIAcwAgACcAcwBlAGwAZgAnACAAaAB0AHQAcABzADoALwAvAHMAdABhAGMAawBlAHgAYwBoAGEAbgBnAGUALgBjAG8AbQAA"; json.entries[2].docIdentifier = 590; json.entries[2].docshellUUID = "{b6c1e18a-d0f5-4ba2-996e-ddd9fc28322a}"; json.entries[2].hasUserInteraction = true; json.entries[2].persist = true; json.entries[2].principalToInherit_base64 = "eyIxIjp7IjAiOiJodHRwczovL3N0YWNrb3ZlcmZsb3cuY29tLyJ9fQ=="; json.entries[2].referrerInfo = "BBoSnxDOS9qmDeAnom1e0AAAAAAAAAAAwAAAAAAAAEYBAAAAGmh0dHBzOi8vc3RhY2tvdmVyZmxvdy5jb20vAAAACAEBAAAAGmh0dHBzOi8vc3RhY2tvdmVyZmxvdy5jb20vAQE="; json.entries[2].resultPrincipalURI = null; json.entries[2].title = "Highest scored questions - Stack Overflow"; json.entries[2].triggeringPrincipal_base64 = "eyIxIjp7IjAiOiJodHRwczovL3N0YWNrb3ZlcmZsb3cuY29tLyJ9fQ=="; json.entries[2].url = "https://stackoverflow.com/questions"; json.entries[3] = {}; json.entries[3].ID = 510; json.entries[3].cacheKey = 0; json.entries[3].csp = "CdntGuXUQAS/4CfOuSPZrAAAAAAAAAAAwAAAAAAAAEYB3pRy0IA0EdOTmQAQS6D9QJIHOlRteE8wkTq4cYEyCMYAAAAC/////wAAAbsBAAAAI2h0dHBzOi8vc3RhY2tvdmVyZmxvdy5jb20vcXVlc3Rpb25zAAAAAAAAAAUAAAAIAAAAEQAAAAj/////AAAACP////8AAAAIAAAAEQAAABkAAAAKAAAAGQAAAAoAAAAZAAAAAQAAABoAAAAJAAAAGv////8AAAAA/////wAAABn/////AAAAGf////8BAAAAAAAAAAAAMXsiMSI6eyIwIjoiaHR0cHM6Ly9zdGFja292ZXJmbG93LmNvbS9xdWVzdGlvbnMifX0AAAABAAAASwB1AHAAZwByAGEAZABlAC0AaQBuAHMAZQBjAHUAcgBlAC0AcgBlAHEAdQBlAHMAdABzADsAIABmAHIAYQBtAGUALQBhAG4AYwBlAHMAdABvAHIAcwAgACcAcwBlAGwAZgAnACAAaAB0AHQAcABzADoALwAvAHMAdABhAGMAawBlAHgAYwBoAGEAbgBnAGUALgBjAG8AbQAA"; json.entries[3].docIdentifier = 592; json.entries[3].docshellUUID = "{b6c1e18a-d0f5-4ba2-996e-ddd9fc28322a}"; json.entries[3].hasUserInteraction = true; json.entries[3].persist = true; json.entries[3].principalToInherit_base64 = "eyIxIjp7IjAiOiJodHRwczovL3N0YWNrb3ZlcmZsb3cuY29tL3F1ZXN0aW9ucyJ9fQ=="; json.entries[3].referrerInfo = "BBoSnxDOS9qmDeAnom1e0AAAAAAAAAAAwAAAAAAAAEYBAAAAI2h0dHBzOi8vc3RhY2tvdmVyZmxvdy5jb20vcXVlc3Rpb25zAAAACAEBAAAAI2h0dHBzOi8vc3RhY2tvdmVyZmxvdy5jb20vcXVlc3Rpb25zAQE="; json.entries[3].resultPrincipalURI = null; json.entries[3].title = "Tags - Stack Overflow"; json.entries[3].triggeringPrincipal_base64 = "eyIxIjp7IjAiOiJodHRwczovL3N0YWNrb3ZlcmZsb3cuY29tL3F1ZXN0aW9ucyJ9fQ=="; json.entries[3].url = "https://stackoverflow.com/tags"; json.entries[4] = {}; json.entries[4].ID = 512; json.entries[4].cacheKey = 0; json.entries[4].csp = "CdntGuXUQAS/4CfOuSPZrAAAAAAAAAAAwAAAAAAAAEYB3pRy0IA0EdOTmQAQS6D9QJIHOlRteE8wkTq4cYEyCMYAAAAC/////wAAAbsBAAAAHmh0dHBzOi8vc3RhY2tvdmVyZmxvdy5jb20vdGFncwAAAAAAAAAFAAAACAAAABEAAAAI/////wAAAAj/////AAAACAAAABEAAAAZAAAABQAAABkAAAAFAAAAGQAAAAEAAAAaAAAABAAAABr/////AAAAAP////8AAAAZ/////wAAABn/////AQAAAAAAAAAAACx7IjEiOnsiMCI6Imh0dHBzOi8vc3RhY2tvdmVyZmxvdy5jb20vdGFncyJ9fQAAAAEAAABLAHUAcABnAHIAYQBkAGUALQBpAG4AcwBlAGMAdQByAGUALQByAGUAcQB1AGUAcwB0AHMAOwAgAGYAcgBhAG0AZQAtAGEAbgBjAGUAcwB0AG8AcgBzACAAJwBzAGUAbABmACcAIABoAHQAdABwAHMAOgAvAC8AcwB0AGEAYwBrAGUAeABjAGgAYQBuAGcAZQAuAGMAbwBtAAA="; json.entries[4].docIdentifier = 594; json.entries[4].docshellUUID = "{b6c1e18a-d0f5-4ba2-996e-ddd9fc28322a}"; json.entries[4].hasUserInteraction = false; json.entries[4].persist = true; json.entries[4].principalToInherit_base64 = "eyIxIjp7IjAiOiJodHRwczovL3N0YWNrb3ZlcmZsb3cuY29tL3RhZ3MifX0="; json.entries[4].referrerInfo = "BBoSnxDOS9qmDeAnom1e0AAAAAAAAAAAwAAAAAAAAEYBAAAAHmh0dHBzOi8vc3RhY2tvdmVyZmxvdy5jb20vdGFncwAAAAgBAQAAAB5odHRwczovL3N0YWNrb3ZlcmZsb3cuY29tL3RhZ3MBAQ=="; json.entries[4].resultPrincipalURI = null; json.entries[4].title = "Users - Stack Overflow"; json.entries[4].triggeringPrincipal_base64 = "eyIxIjp7IjAiOiJodHRwczovL3N0YWNrb3ZlcmZsb3cuY29tL3RhZ3MifX0="; json.entries[4].url = "https://stackoverflow.com/users"; json.hidden = false; json.index = 3; json.lastAccessed = 1651407567904; json.requestedIndex = 0; json.searchMode = null; json.userContextId = 0
Just index entries by index minus one? .entries[.index - 1] Online demo
The last item in entries is not necessarily the tab that was opened. [.index - 1] only works if user_pref("browser.sessionstore.max_serialize_forward", 0); cf. https://wiki.mozilla.org/Firefox/session_restore#Browser_settings
How to Create Parametric Survival Learner for MLR in R
I am following the instructions (https://mlr.mlr-org.com/articles/tutorial/create_learner.html) to create a parametric survival learner to use with MLR. My code is below. When I try to make the MakeLearner(id = "AFT", "surv.parametric"), I get an error dist is missing and no default is set even though I already specified the dist default in my code to be "weibull". makeRLearner.surv.parametric = function() { makeRLearnerSurv( cl = "surv.parametric", package = "survival", par.set = makeParamSet( makeDiscreteLearnerParam(id = "dist", default = "weibull", values = c("weibull", "exponential", "lognormal", "loglogistic")), ), properties = c("numerics", "factors", "weights", "prob", "rcens"), name = "Parametric Survival Model", short.name = "Parametric", note = "This is created based on MLR3 surv.parametric learner" ) } trainLearner.surv.parametric = function (.learner, .task, .subset, .weights = NULL, ...) { f = getTaskFormula(.task) data = getTaskData(.task, subset = .subset) if (is.null(.weights)) { mod = survival::survreg(formula = f, data = data, ...) } else { mod = survival::survreg(formula = f, data = data, weights = .weights, ...) } mod } predictLearner.surv.parametric = function (.learner, .model, .newdata, ...) { survival::predict.survreg(.model$learner.model, newdata = .newdata, type = "response", ...) }
Based on here, the prediction function needs to return linear predictors and that would be lp not response. Also, the cindex function of MLR does not seem to be consistent with the output of SurvReg. Based on this discussion, adding a minus seems to resolve the issue. So the prediction function would be as below. predictLearner.surv.reg = function(.learner, .model, .newdata, ...) { -predict(.model$learner.model, newdata = .newdata, type = "lp", ...) }
GNU Octave producing ans even when semicolon is specified when using vectors
I'm new to GNU Octave and I've written a script that works fine, but its producing a weird output to the command line. The script used is for plotting a graph point by point on button click. The code is x_axis = [0.00000000000000E+00,0.00000000000000E+00,0.00000000000000E+00,0.00000000000000E+00,5.00000000000000E-12,1.30000000000000E-11,1.94000000000000E-11,2.96400000000000E-11,3.37360000000000E-11,4.02896000000000E-11,4.55324800000000E-11,5.39210880000000E-11,6.06319744000000E-11,6.60006835200000E-11,7.02956508160000E-11,7.37316246528000E-11,7.51060141875200E-11,7.73050374430720E-11,8.08234746519552E-11,8.36382244190618E-11,8.81418240464323E-11,8.99432638973805E-11,9.28255676588976E-11,9.51314106681113E-11,9.69760850754822E-11,9.99275641272758E-11,1.02288747368711E-10,1.04177693961858E-10,1.07200008510895E-10,1.09617860150124E-10,1.11552141461508E-10,1.14646991559721E-10,1.17122871638292E-10,1.21084279764005E-10,1.24253406264576E-10,1.26788707465032E-10,1.30845189385763E-10,1.34090374922347E-10,1.36686523351614E-10,1.40840360838442E-10,1.42501895833173E-10,1.45160351824743E-10,1.49413881411255E-10,1.52816705080464E-10,1.53497269814306E-10,1.54586173388453E-10,1.56328419107088E-10,1.59116012256905E-10,1.61346086776758E-10,1.63130146392640E-10,1.65984641778052E-10,1.68268238086382E-10,1.70095115133045E-10,1.70825865951711E-10,1.71995067261575E-10,1.73865789357359E-10,1.75362367033986E-10,1.77756891316589E-10,1.79672510742671E-10,1.80438758513104E-10,1.81051756729450E-10,1.82032553875605E-10,1.83601829309451E-10,1.84857249656529E-10,1.86865922211852E-10,1.88472860256111E-10,1.89758410691519E-10,1.90272630865681E-10,1.90684007005012E-10,1.91342208827940E-10,1.91868770286283E-10,1.92711268619632E-10,1.93385267286310E-10,1.93924466219653E-10,1.94787184513002E-10,1.95477359147681E-10,1.96029498855424E-10,1.96912922387814E-10,1.97619661213725E-10,1.98750443335183E-10,2.00559694729516E-10,2.02007095844983E-10,2.03165016737356E-10,2.05017690165153E-10,2.07981967649628E-10,2.09167678643418E-10,2.10116247438450E-10,2.11633957510502E-10,2.14062293625784E-10,2.15033628071897E-10,2.15810695628787E-10,2.17054003719812E-10,2.19043296665451E-10,2.19839013843706E-10,2.21112161328915E-10,2.23149197305250E-10,2.24778826086317E-10,2.26082529111172E-10,2.28168453950938E-10,2.29837193822751E-10,2.31172185720202E-10,2.33308172756123E-10,2.36725752013596E-10,2.42193878825554E-10,2.46568380275120E-10,2.53567582594426E-10,2.59166944449870E-10,2.68125923418581E-10,2.82460289768519E-10,3.05395275928420E-10,3.23743264856341E-10,3.53100047141014E-10,4.00070898796491E-10,4.18859239458682E-10,4.48920584518187E-10,4.97018736613395E-10,5.73975779965729E-10,6.35541414647596E-10,7.34046430138582E-10,8.12850442531372E-10,9.38936862359835E-10,1.14067513408538E-09,1.30206575146581E-09,1.56029073927450E-09,1.97345071976841E-09,2.63450668855866E-09,3.16335146359086E-09,3.58642728361663E-09,4.26334859565785E-09,4.80488564529082E-09,5.23811528499720E-09,5.93128270852741E-09,6.48581664735158E-09,7.37307094947024E-09,8.08287439116518E-09,8.65071714452112E-09,9.55926554989064E-09,1.00000000000000E-08,1.14536774485912E-08,1.37795613663372E-08,1.75009756347307E-08,2.25009756347307E-08,2.75009756347307E-08,3.25009756347307E-08,3.75009756347307E-08,4.25009756347307E-08,4.75009756347307E-08,5.25009756347307E-08,5.75009756347307E-08,6.25009756347307E-08,6.75009756347307E-08,7.25009756347307E-08,7.75009756347307E-08,8.25009756347307E-08,8.75009756347307E-08,9.25009756347307E-08,9.75009756347307E-08,1.00000000000000E-07]; y_axis = [-9.39173350887998E-32,-1.86650535110635E-31,1.31115948364582E-27,1.94509722242530E-25,-1.00344588881891E-21,-5.87459290306659E-21,-1.37073757649753E-20,-4.86147958403305E-20,-7.63974343257361E-20,-1.71040940512147E-19,-3.38920214313857E-19,-1.18885155233808E-18,-3.51328830508339E-18,-8.78799288101173E-18,-1.88243629379682E-17,-3.51802689061712E-17,-4.49449528359159E-17,-6.79565282967628E-17,-1.34186349095581E-16,-2.31297635209485E-16,-5.71110439628175E-16,-8.08187727353700E-16,-1.44731539963045E-15,-2.29659329899228E-15,-3.32226881207743E-15,-6.07452021226282E-15,-9.77314790670134E-15,-1.42769268847667E-14,-2.64585536036781E-14,-4.29496639316416E-14,-6.31287803028352E-14,-1.17943950739760E-13,-1.92469245877504E-13,-4.25063881290420E-13,-7.89483522299793E-13,-1.28920665234410E-12,-2.84902213070563E-12,-5.29522377461008E-12,-8.65384357585056E-12,-1.91533007497040E-11,-2.59080275155903E-11,-4.27299516300553E-11,-9.51054948026229E-11,-1.77798774195455E-10,-1.99495474499103E-10,-2.43091404639964E-10,-3.34682557590070E-10,-5.57798852090487E-10,-8.32337198451749E-10,-1.14374909944538E-09,-1.91120020411426E-09,-2.85551127611928E-09,-3.92387180151988E-09,-4.43758170868350E-09,-5.43466810920640E-09,-7.50901087225516E-09,-9.66190860282403E-09,-1.44338575031994E-08,-1.96753685365158E-08,-2.21629406913249E-08,-2.43924996003962E-08,-2.84551960847752E-08,-3.62421339965087E-08,-4.36757128201692E-08,-5.84585839648811E-08,-7.30091830091753E-08,-8.67125059918094E-08,-9.26675103463482E-08,-9.77183969342209E-08,-1.06370533972462E-07,-1.13697585523745E-07,-1.26355935516070E-07,-1.37221352317618E-07,-1.46440395269411E-07,-1.62386536344951E-07,-1.76081449361409E-07,-1.87705716998312E-07,-2.07841349695580E-07,-2.25153990904328E-07,-2.55742641792671E-07,-3.12420515197923E-07,-3.64195554678131E-07,-4.09799710873070E-07,-4.89326201699816E-07,-6.21322334401833E-07,-6.75650203943832E-07,-7.18722478876752E-07,-7.83426435958378E-07,-8.72851070500037E-07,-9.06548231493498E-07,-9.31940701989342E-07,-9.68292309353881E-07,-1.01648017433132E-06,-1.03427589223822E-06,-1.05916417720008E-06,-1.09132796931090E-06,-1.11290602031335E-06,-1.12787010767833E-06,-1.14726311445438E-06,-1.16042155982867E-06,-1.16970022782536E-06,-1.18223247183124E-06,-1.19866965764282E-06,-1.22109633633903E-06,-1.23823245732513E-06,-1.26682187628956E-06,-1.29108062409592E-06,-1.33389344981185E-06,-1.41022558838021E-06,-1.54386804821518E-06,-1.65559050610987E-06,-1.84054551863630E-06,-2.14563662056096E-06,-2.27002646291102E-06,-2.47144856400291E-06,-2.80019687100178E-06,-3.34149054275745E-06,-3.78721156086594E-06,-4.52250561798966E-06,-5.12956538504310E-06,-6.13331392887164E-06,-7.81732846719364E-06,-9.22848148341832E-06,-1.15922677819807E-05,-1.56187309065232E-05,-2.25935707280579E-05,-2.85748785714530E-05,-3.35772955724184E-05,-4.19193206861019E-05,-4.88646689055068E-05,-5.45719983022503E-05,-6.39410090676521E-05,-7.16337339299082E-05,-8.42406203052840E-05,-9.45692560450757E-05,-1.02966392937475E-04,-1.16604302814647E-04,-1.23311931601159E-04,-1.23712116457864E-04,-1.23353312847230E-04,-1.22549100652487E-04,-1.21499037280975E-04,-1.20528308967738E-04,-1.19627601938410E-04,-1.18783794770588E-04,-1.17986366199978E-04,-1.17227234731004E-04,-1.16500110271064E-04,-1.15800272295338E-04,-1.15124231439077E-04,-1.14469284659222E-04,-1.13833235454863E-04,-1.13214238663767E-04,-1.12610729347588E-04,-1.12021382913759E-04,-1.11445101253981E-04,-1.10880995314033E-04,-1.10602993829452E-04]; sub_x = [x_axis(1), x_axis(2)]; sub_y = [x_axis(2), y_axis(3)]; plot(sub_x,sub_y); hold on; i = 2; buttons=1; while(buttons==1) { [x(1),y(1),buttons(1)] = ginput(1); i=i+1; sub_x=[x_axis(i-1) , x_axis(i)]; sub_y=[y_axis(i-1) , y_axis(i)]; plot(sub_x,sub_y, '.-'); } endwhile; hold off; Now, the output it produces is like this- ans = { [1,1] = 0.42028 [2,1] = 3 [3,1] = 0 0 [4,1] = -1.8665e-31 1.3112e-27 [5,1] = -44.552 } ans = { [1,1] = 0.42028 [2,1] = 4 [3,1] = 0 0 [4,1] = 1.3112e-27 1.9451e-25 [5,1] = -43.579 } I have no clue what this output means or how to prevent this from popping up.
Keras handling large dataset which cannot fit into memory
I'm working on facial expression recognition, and I'm using Keras. I've collected many datasets, and then I have applied data augmentation on the images, I've got about 500 000 images saved (as pixels) on a .csv file (same format as fer2013.csv). This is the code I'm using : def Zerocenter_ZCA_whitening_Global_Contrast_Normalize(list): Intonumpyarray = numpy.asarray(list) data = Intonumpyarray.reshape(img_width,img_height) data2 = ZeroCenter(data) data3 = zca_whitening(flatten_matrix(data2)).reshape(img_width,img_height) data4 = global_contrast_normalize(data3) data5 = numpy.rot90(data4,3) return data5 def load_data(): train_x = [] train_y = [] val_x = [] val_y = [] test_x = [] test_y = [] f = open('ALL.csv') csv_f = csv.reader(f) for row in csv_f: if str(row[2]) == "Training": temp_list_train = [] for pixel in row[1].split(): temp_list_train.append(int(pixel)) data = Zerocenter_ZCA_whitening_Global_Contrast_Normalize(temp_list_train) train_y.append(int(row[0])) train_x.append(data.reshape(data_resh).tolist()) elif str(row[2]) == "PublicTest": temp_list_validation = [] for pixel in row[1].split(): temp_list_validation.append(int(pixel)) data = Zerocenter_ZCA_whitening_Global_Contrast_Normalize(temp_list_validation) val_y.append(int(row[0])) val_x.append(data.reshape(data_resh).tolist()) elif str(row[2]) == "PrivateTest": temp_list_test = [] for pixel in row[1].split(): temp_list_test.append(int(pixel)) data = Zerocenter_ZCA_whitening_Global_Contrast_Normalize(temp_list_test) test_y.append(int(row[0])) test_x.append(data.reshape(data_resh).tolist()) return train_x, train_y, val_x, val_y, test_x, test_y And then I load data and feed them to the generator : Train_x, Train_y, Val_x, Val_y, Test_x, Test_y = load_data() Train_x = numpy.asarray(Train_x) Train_x = Train_x.reshape(Train_x.shape[0],img_rows,img_cols) Test_x = numpy.asarray(Test_x) Test_x = Test_x.reshape(Test_x.shape[0],img_rows,img_cols) Val_x = numpy.asarray(Val_x) Val_x = Val_x.reshape(Val_x.shape[0],img_rows,img_cols) Train_x = Train_x.reshape(Train_x.shape[0], img_rows, img_cols, 1) Test_x = Test_x.reshape(Test_x.shape[0], img_rows, img_cols, 1) Val_x = Val_x.reshape(Val_x.shape[0], img_rows, img_cols, 1) Train_x = Train_x.astype('float32') Test_x = Test_x.astype('float32') Val_x = Val_x.astype('float32') Train_y = np_utils.to_categorical(Train_y, nb_classes) Test_y = np_utils.to_categorical(Test_y, nb_classes) Val_y = np_utils.to_categorical(Val_y, nb_classes) datagen = ImageDataGenerator( featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, width_shift_range=0.2, height_shift_range=0.2, horizontal_flip=True, shear_range=0.03, zoom_range=0.03, vertical_flip=False) datagen.fit(Train_x) model.fit_generator(datagen.flow(Train_x, Train_y, batch_size=batch_size), samples_per_epoch=Train_x.shape[0], nb_epoch=nb_epoch, validation_data=(Val_x, Val_y)) When I run the code, RAM usage gets bigger and bigger until the pc freezes (I've have 16 Gb). It get stuck when loading_data() is called. Any solution for this problem that can fits my code ?
Seems to be a duplicate of this question. Basically, you'll have to use fit_generator() instead of fit() and pass in a function that loads the data into your model one batch at a time instead of all at once.
How to add rows to TableElement in Dart?
I'm playing with Dart, and I'm trying to create a new TableElement with a header and one row in the tbody. TableElement table = new TableElement(); Element head = table.createTHead(); TableRowElement headerRow = table.tHead.insertRow(-1); headerRow.insertCell(0).text = "9"; headerRow.insertCell(1).text = "aaa"; headerRow.insertCell(2).text = "bbb"; headerRow.insertCell(3).text = "ccc"; var tBody = table.createTBody(); TableRowElement newLine = table.insertRow(-1); // add at the end newLine.insertCell(0).text = "9"; newLine.insertCell(1).text = "aaa"; newLine.insertCell(2).text = "bbb"; newLine.insertCell(3).text = "ccc"; Unfortunately, both rows end up in the thead section. On top of that, if I leave only TableElement table = new TableElement(); var tBody = table.createTBody(); TableRowElement newLine = table.insertRow(-1); // add at the end newLine.insertCell(0).text = "9"; newLine.insertCell(1).text = "aaa"; newLine.insertCell(2).text = "bbb"; newLine.insertCell(3).text = "ccc"; the row gets to tbody section, as expected. Any Ideas? Dart SDK 9474.
In your example, you are adding the first row directly into the table header that you have created. But the second row, you are trying to add directly into your table (not into your TBody) Try the following: TableElement table = new TableElement(); // ... See below ... var tBody = table.createTBody(); TableElement newLine = tBody.insertRow(-1); newLine.insertCell(0).text = "9"; newLine.insertCell(1).text = "aaa"; newLine.insertCell(2).text = "bbb"; newLine.insertCell(3).text = "ccc"; As mentioned in the comments, currently dart:html library does not support table header elements. As such a little bit of a work around needs to be done. The create table headers you can use the following: Element head = table.createTHead(); TableRowElement headerRow = table.tHead.insertRow(-1); var cell = new Element.tag('th'); cell.text = '9'; headerRow.insertAdjacentElement('beforeend', cell); cell = new Element.tag('th'); cell.text = 'aaa'; headerRow.insertAdjacentElement('beforeend', cell); cell = new Element.tag('th'); cell.text = 'bbb'; headerRow.insertAdjacentElement('beforeend', cell); cell = new Element.tag('th'); cell.text = 'ccc'; headerRow.insertAdjacentElement('beforeend', cell); // ... See above ... Note however that the insertAdjacentElement does not work for firefox (as they chose not to implement that JavaScript method). And alternative is to use: headerRow.nodes.add(cell); Note that this is a work around and does not allow for indexing in the same way as insertCell and involves much more work to create the cells individually. This provides a work around util the two bugs listed in comments are resolved.
The below code worked fine with me: TableElement table2 = new TableElement(); table2.style.width='100%'; var tBody2 = table2.createTBody(); table2.tHead.insertRow(-1)..insertCell(0).nodes.add(new Element.tag('th')..text = '1') ..insertCell(1).nodes.add(new Element.tag('th')..text = '2') ..insertCell(2).nodes.add( new Element.tag('th')..text = '3') ..insertCell(3).nodes.add( new Element.tag('th')..text = '4'); tBody2.insertRow(0)..insertCell(0).text = "9" ..insertCell(1).text = "aaa" ..insertCell(2).text = "bbb" ..insertCell(3).text = "ccc"; tBody2.insertRow(1)..insertCell(0).text = "9" ..insertCell(1).text = "aaa" ..insertCell(2).text = "bbb" ..insertCell(3).text = "ccc"; tBody2.insertRow(2)..insertCell(0).text = "9" ..insertCell(1).text = "aaa" ..insertCell(2).text = "bbb" ..insertCell(3).text = "ccc";