cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
%3CLINGO-SUB%20id%3D%22lingo-sub-335794%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EComment%20trouver%20la%20moyenne%20des%20%C3%A9chantillons%20%C3%A0%20intervalles%20al%C3%A9atoires%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-335794%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EJ'ai%20un%20fichier%20csv%20qui%20stocke%20les%20valeurs%20temporaires.%20Je%20dois%20trouver%20la%20moyenne%20du%20groupe%20pour%20certains%20ensembles%20d'%C3%A9chantillons%20selon%20les%20%C3%A9tapes%20ci-dessous%3A%3C%2FP%3E%3CP%3E1.Faites%20en%20sorte%20que%20toutes%20les%20valeurs%20temporaires%20inf%C3%A9rieures%20%C3%A0%2025%20soient%20%C3%A9gales%20%C3%A0%20z%C3%A9ro%20post_processus%20iecolumn%3C%2FP%3E%3CP%3E2.%20La%20colonne%20group_avg%20est%20d%C3%A9riv%C3%A9e%20en%20ignorant%20les%20lignes%20avec%20plus%20de%20ou%20%C3%A9gal%20%C3%A0%204%20z%C3%A9ros%20cons%C3%A9cutifs.%20Suivi%20du%20calcul%20de%20la%20moyenne%20du%20groupe%20d'%C3%A9chantillons%20comme%20indiqu%C3%A9%20ci-dessous%3C%2FP%3E%3CP%3E3.%20La%20colonne%20final_average%20correspond%20aux%20r%C3%A9sultats%20g%C3%A9n%C3%A9r%C3%A9s%20%C3%A0%20partir%20de%20la%20colonne%20group_avg%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EComment%20pouvons-nous%20%C3%A9crire%20ce%20processus%20en%20utilisant%20jsl%3F%3C%2FP%3E%3CP%3EJoindre%20le%20fichier%20csv%3C%2FP%3E%3CP%3ELe%20r%C3%A9sultat%20final%20est%20d%C3%A9finitif%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3E%20_average%20comme%20dans%20le%20tableau%20ci-dessous%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22jojmp_0-1605845994525.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jojmp_0-1605845994525.png%22%20style%3D%22width%3A%2097px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F28497i81222E48BFCD84BA%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22jojmp_0-1605845994525.png%22%20alt%3D%22jojmp_0-1605845994525.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-335794%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CLINGO-LABEL%3ETableau%20de%20donn%C3%A9es%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EScripting%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-335813%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Comment%20trouver%20la%20moyenne%20des%20%C3%A9chantillons%20%C3%A0%20intervalles%20al%C3%A9atoires%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-335813%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EVoici%20un%20script%20qui%20cr%C3%A9e%20votre%20table%20de%20donn%C3%A9es%20avec%20uniquement%20la%20colonne%20TEMP%2C%20puis%20les%20colonnes%20restantes%20sont%20cr%C3%A9%C3%A9es%20et%20une%20formule%20est%20utilis%C3%A9e%20pour%20les%20remplir.%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0Adt%20%3D%20New%20Table(%20%22temp_temp%22%2C%0A%20Add%20Rows(%2054%20)%2C%0A%20New%20Column(%20%22TEMP%22%2C%0A%20%20Numeric%2C%0A%20%20%22Continuous%22%2C%0A%20%20Format(%20%22Best%22%2C%2012%20)%2C%0A%20%20Set%20Values(%0A%20%20%20%5B23.23019577%2C%2023.44946668%2C%2023.56111955%2C%2023.47601143%2C%2023.36428639%2C%0A%20%20%2023.24016499%2C%2032.42091411%2C%2023%2C%2032.26821731%2C%2032.14990084%2C%2032.42091411%2C%0A%20%20%2032.26821731%2C%2032.14990084%2C%2023.23019577%2C%2023.44946668%2C%2023.56111955%2C%0A%20%20%2023.47601143%2C%2023.36428639%2C%2023.24016499%2C%2032.15353181%2C%2032.16785998%2C%2021%2C%0A%20%20%2032.502366%2C%2032.16261133%2C%2032.15757688%2C%2032.16790474%2C%2023.23019577%2C%0A%20%20%2023.44946668%2C%2023.56111955%2C%2023.47601143%2C%2023.36428639%2C%2023.24016499%2C%0A%20%20%2032.42091411%2C%2010%2C%2032.26821731%2C%2032.14990084%2C%2032.41334166%2C%2032.17456755%2C%0A%20%20%2032.52383338%2C%2032.17310331%2C%2019.28571429%2C%2019.28571429%2C%2019.28571429%2C%0A%20%20%2019.28571429%2C%2034.62948075%2C%2034.28766971%2C%2034.29470736%2C%2034.61532486%2C%0A%20%20%2034.386807%2C%2034.36554216%2C%2034.58410721%2C%2034.28726312%2C%2023.57142857%2C%0A%20%20%2023.57142857%5D%0A%20%20)%0A%20)%0A)%3B%0A%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%20%22post%20process%22%2C%20formula(%20If(%20%3ATEMP%20%26lt%3B%3D%2025%2C%200%2C%20%3ATEMP%20)%20)%20)%3B%0Adt%3Apost%20process%20%26lt%3B%26lt%3B%20delete%20formula%3B%0A%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%20%22group_avg%22%2C%0A%20formula(%0A%20%20value%20%3D%20.%3B%0A%20%20If(%20Row()%20%3D%3D%201%2C%0A%20%20%20flag%20%3D%200%3B%0A%20%20%20zeroCounter%20%3D%200%3B%0A%20%20)%3B%0A%20%20If(%20flag%20%3D%3D%200%20%26amp%3B%20%3Apost%20process%20%26gt%3B%200%2C%0A%20%20%20flag%20%3D%201%3B%0A%20%20%20captureMatrix%20%3D%20%5B%5D%3B%0A%20%20%20Show(%20%22start%22%2C%20Row()%2C%20flag%20)%3B%0A%20%20)%3B%0A%20%20If(%20%3Apost%20process%20%3D%3D%200%20%26amp%3B%20flag%20%3D%3D%201%2C%0A%20%20%20zeroCounter%0A%20%20%20%2B%2B)%3B%0A%20%20If(%20flag%20%3D%3D%201%2C%0A%20%20%20captureMatrix%20%3D%20captureMatrix%20%7C%7C%20Matrix(%20%3Apost%20process%20)%3B%0A%20%20%20Show(%20%22cap%22%2C%20Row()%2C%20captureMatrix%20)%3B%0A%20%20%20If(%20zeroCounter%20%3D%3D%204%20%7C%20Row()%20%3D%3D%20N%20Rows(%20dt%20)%2C%0A%20%20%20%20For(%20i%20%3D%20N%20Cols(%20captureMatrix%20)%2C%20i%20%26gt%3B%3D%201%2C%20i--%2C%0A%20%20%20%20%20If(%20captureMatrix%5Bi%5D%20!%3D%200%2C%0A%20%20%20%20%20%20Break()%2C%0A%20%20%20%20%20%20captureMatrix%5Bi%5D%20%3D%20.%0A%20%20%20%20%20)%0A%20%20%20%20)%3B%0A%20%20%20%20value%20%3D%20Mean(%20captureMatrix%20)%3B%0A%20%20%20%20Show(%20value%20)%3B%0A%20%20%20%20Show(%20Row()%2C%20captureMatrix%2C%20zeroCounter%2C%20Index(%201%2C%20N%20Cols(%20captureMatrix%20)%20-%20(zeroCounter%20-%201)%20)%20)%3B%0A%20%20%20%20flag%20%3D%200%3B%0A%20%20%20%20zeroCounter%20%3D%200%3B%0A%20%20%20%20Show(%20flag%20)%3B%0A%20%20%20%20captureMatrix%20%3D%20%5B%5D%3B%0A%20%20%20)%3B%0A%20%20)%3B%0A%20%20value%3B%0A%20)%0A)%3B%0A%0Adt%20%26lt%3B%26lt%3B%20new%20column(%22final%20Avg%22%2C%0A%20formula(%0A%20%20if(row()%3D%3D1%2C%0A%20%20%20theRows%20%3D%20current%20data%20table()%20%26lt%3B%26lt%3B%20get%20rows%20where(isMissing(%3Agroup_avg)%3D%3D0)%3B%0A%20%20)%3B%0A%20%20If(row()%26lt%3B%3D%20nrows(theRows)%2C%0A%20%20%20value%3D%3Agroup_avg%5BtheRows%5BRow()%5D%5D%2C%0A%20%20%20value%3D.%0A%20%20)%0A%20)%0A)%3B%0A%0A%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-335816%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Comment%20trouver%20la%20moyenne%20des%20%C3%A9chantillons%20%C3%A0%20intervalles%20al%C3%A9atoires%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-335816%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ECe%20script%20fonctionne%20tr%C3%A8s%20bien%20pour%20les%20petits%20fichiers.%20Mais%20dans%20le%20cas%20de%20fichiers%20volumineux%20o%C3%B9%20nous%20avons%2016000%20z%C3%A9ros%20au%20lieu%20de%204%20JMP%20cesse%20de%20r%C3%A9pondre.%20Existe-t-il%20un%20moyen%20d'emp%C3%AAcher%20cela%20et%20d'ex%C3%A9cuter%20le%20script%20sans%20se%20bloquer%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-335842%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Comment%20trouver%20la%20moyenne%20des%20%C3%A9chantillons%20%C3%A0%20intervalles%20al%C3%A9atoires%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-335842%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EJe%20soup%C3%A7onne%20que%20le%20probl%C3%A8me%20est%20que%2C%20par%20erreur%2C%20j'ai%20laiss%C3%A9%20plusieurs%20instructions%20%22Show%20()%22%20dans%20le%20code%2C%20ce%20qui%20a%20forc%C3%A9%20beaucoup%20d'%C3%A9criture%20dans%20le%20journal%20JMP.%3C%2FP%3E%0A%3CP%3ECi-dessous%20se%20trouve%20la%20sp%C3%A9cification%20de%20la%20colonne%20%C2%ABpost-process%C2%BB%2C%20qui%20est%20la%20partie%20que%20je%20suppose%20avoir%20le%20probl%C3%A8me%20qui%20bloque%20JMP.Essayez%20de%20l'ex%C3%A9cuter%20et%20voyez%20s'il%20fonctionnera%20sans%20se%20bloquer%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%20%26lt%3B%26lt%3B%20New%20Column(%20%22group_avg%22%2C%0A%20formula(%0A%20%20value%20%3D%20.%3B%0A%20%20If(%20Row()%20%3D%3D%201%2C%0A%20%20%20flag%20%3D%200%3B%0A%20%20%20zeroCounter%20%3D%200%3B%0A%20%20)%3B%0A%20%20If(%20flag%20%3D%3D%200%20%26amp%3B%20%3Apost%20process%20%26gt%3B%200%2C%0A%20%20%20flag%20%3D%201%3B%0A%20%20%20captureMatrix%20%3D%20%5B%5D%3B%0A%20%20)%3B%0A%20%20If(%20%3Apost%20process%20%3D%3D%200%20%26amp%3B%20flag%20%3D%3D%201%2C%0A%20%20%20zeroCounter%0A%20%20%20%2B%2B)%3B%0A%20%20If(%20flag%20%3D%3D%201%2C%0A%20%20%20captureMatrix%20%3D%20captureMatrix%20%7C%7C%20Matrix(%20%3Apost%20process%20)%3B%0A%20%20%20If(%20zeroCounter%20%3D%3D%204%20%7C%20Row()%20%3D%3D%20N%20Rows(%20dt%20)%2C%0A%20%20%20%20%2F*For(%20i%20%3D%20N%20Cols(%20captureMatrix%20)%2C%20i%20%26gt%3B%3D%201%2C%20i--%2C%0A%20%20%20%20%20If(%20captureMatrix%5Bi%5D%20!%3D%200%2C%0A%20%20%20%20%20%20Break()%2C%0A%20%20%20%20%20%20captureMatrix%5Bi%5D%20%3D%20.%0A%20%20%20%20%20)%0A%20%20%20%20)%3B*%2F%0A%20%20%20%20if(%20Row()%20%3D%3D%20N%20Rows(%20dt%20)%2C%20zerocounter%2B%2B%20)%3B%0A%20%20%20%20value%20%3D%20Mean(%20captureMatrix%5B%201%3A%3A%20ncols(captureMatrix)%20-%20(zeroCounter%20-%201)%5D%20)%3B%0A%20%20%20%20flag%20%3D%200%3B%0A%20%20%20%20zeroCounter%20%3D%200%3B%0A%20%20%20%20captureMatrix%20%3D%20%5B%5D%3B%0A%20%20%20)%3B%0A%20%20)%3B%0A%20%20value%3B%0A%20)%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-335922%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Comment%20trouver%20la%20moyenne%20des%20%C3%A9chantillons%20%C3%A0%20intervalles%20al%C3%A9atoires%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-335922%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ELe%20premier%20script%20donne%20la%20bonne%20r%C3%A9ponse%20mais%20la%20sortie%20des%20deux%20scripts%20n'est%20pas%20la%20m%C3%AAme%2C%20pourquoi%20avez-vous%20comment%C3%A9%20une%20partie%20du%20code%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-335925%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Comment%20trouver%20la%20moyenne%20des%20%C3%A9chantillons%20%C3%A0%20intervalles%20al%C3%A9atoires%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-335925%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ELa%20deuxi%C3%A8me%20version%20du%20code%20est%20plus%20efficace.%20Compte%20tenu%20de%20la%20quantit%C3%A9%20de%20donn%C3%A9es%20que%20vous%20utilisez%2C%20j'ai%20pens%C3%A9%20que%20cela%20aiderait.Il%20devrait%20fournir%20les%20m%C3%AAmes%20r%C3%A9sultats.Si%20ce%20n'est%20pas%20le%20cas%2C%20vous%20pouvez%20simplement%20essayer%20de%20supprimer%20toutes%20les%20instructions%20Show%20()%20de%20la%20premi%C3%A8re%20version%20du%20code%2C%20et%20si%20cela%20fonctionne.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
jojmp
Level III

How to find the average of samples at random intervals?

I have a csv file that stores temp values. I have to find the group average for certain set of samples according to below steps:

1. Make all temp values les than 25 equal to zero i.e.column post_process

2. group_avg column is derived by ignoring rows with greater than or equal to 4 consecutive zeroes. Followed by calculating the average of the group of samples as shown below

3. final_average column is the results generated from group_avg column

 

How can we script this process using jsl?

Attaching the csv file

Final result is final_average as in the table below:

jojmp_0-1605845994525.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to find the average of samples at random intervals?

I suspect the issue is that by mistake, I left several "Show()" statements in the code, which forced a lot of writing to the JMP log.

Below is the "post process" column specification, which is the part that I assume is having the issue that is making JMP hang.  Try running it and see if it will run without hanging

dt << New Column( "group_avg",
	formula(
		value = .;
		If( Row() == 1,
			flag = 0;
			zeroCounter = 0;
		);
		If( flag == 0 & :post process > 0,
			flag = 1;
			captureMatrix = [];
		);
		If( :post process == 0 & flag == 1,
			zeroCounter
			++);
		If( flag == 1,
			captureMatrix = captureMatrix || Matrix( :post process );
			If( zeroCounter == 4 | Row() == N Rows( dt ),
				/*For( i = N Cols( captureMatrix ), i >= 1, i--,
					If( captureMatrix[i] != 0,
						Break(),
						captureMatrix[i] = .
					)
				);*/
				if( Row() == N Rows( dt ), zerocounter++ );
				value = Mean( captureMatrix[ 1:: ncols(captureMatrix) - (zeroCounter - 1)] );
				flag = 0;
				zeroCounter = 0;
				captureMatrix = [];
			);
		);
		value;
	)
);
Jim

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: How to find the average of samples at random intervals?

Here is a script that creates your data table with just the TEMP column, and then the remaining columns are created and formula are used to populate them.

Names Default To Here( 1 );
dt = New Table( "temp_temp",
	Add Rows( 54 ),
	New Column( "TEMP",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values(
			[23.23019577, 23.44946668, 23.56111955, 23.47601143, 23.36428639,
			23.24016499, 32.42091411, 23, 32.26821731, 32.14990084, 32.42091411,
			32.26821731, 32.14990084, 23.23019577, 23.44946668, 23.56111955,
			23.47601143, 23.36428639, 23.24016499, 32.15353181, 32.16785998, 21,
			32.502366, 32.16261133, 32.15757688, 32.16790474, 23.23019577,
			23.44946668, 23.56111955, 23.47601143, 23.36428639, 23.24016499,
			32.42091411, 10, 32.26821731, 32.14990084, 32.41334166, 32.17456755,
			32.52383338, 32.17310331, 19.28571429, 19.28571429, 19.28571429,
			19.28571429, 34.62948075, 34.28766971, 34.29470736, 34.61532486,
			34.386807, 34.36554216, 34.58410721, 34.28726312, 23.57142857,
			23.57142857]
		)
	)
);

dt << New Column( "post process", formula( If( :TEMP <= 25, 0, :TEMP ) ) );
dt:post process << delete formula;

dt << New Column( "group_avg",
	formula(
		value = .;
		If( Row() == 1,
			flag = 0;
			zeroCounter = 0;
		);
		If( flag == 0 & :post process > 0,
			flag = 1;
			captureMatrix = [];
			Show( "start", Row(), flag );
		);
		If( :post process == 0 & flag == 1,
			zeroCounter
			++);
		If( flag == 1,
			captureMatrix = captureMatrix || Matrix( :post process );
			Show( "cap", Row(), captureMatrix );
			If( zeroCounter == 4 | Row() == N Rows( dt ),
				For( i = N Cols( captureMatrix ), i >= 1, i--,
					If( captureMatrix[i] != 0,
						Break(),
						captureMatrix[i] = .
					)
				);
				value = Mean( captureMatrix );
				Show( value );
				Show( Row(), captureMatrix, zeroCounter, Index( 1, N Cols( captureMatrix ) - (zeroCounter - 1) ) );
				flag = 0;
				zeroCounter = 0;
				Show( flag );
				captureMatrix = [];
			);
		);
		value;
	)
);

dt << new column("final Avg",
	formula(
		if(row()==1,
			theRows = current data table() << get rows where(isMissing(:group_avg)==0);
		);
		If(row()<= nrows(theRows),
			value=:group_avg[theRows[Row()]],
			value=.
		)
	)
);

Jim
jojmp
Level III

Re: How to find the average of samples at random intervals?

This scripts works fine for small files. But in case of large files where we have 16000 zeroes instead of 4 JMP stops responding. Is there any way to prevent this and run the script without hang?

txnelson
Super User

Re: How to find the average of samples at random intervals?

I suspect the issue is that by mistake, I left several "Show()" statements in the code, which forced a lot of writing to the JMP log.

Below is the "post process" column specification, which is the part that I assume is having the issue that is making JMP hang.  Try running it and see if it will run without hanging

dt << New Column( "group_avg",
	formula(
		value = .;
		If( Row() == 1,
			flag = 0;
			zeroCounter = 0;
		);
		If( flag == 0 & :post process > 0,
			flag = 1;
			captureMatrix = [];
		);
		If( :post process == 0 & flag == 1,
			zeroCounter
			++);
		If( flag == 1,
			captureMatrix = captureMatrix || Matrix( :post process );
			If( zeroCounter == 4 | Row() == N Rows( dt ),
				/*For( i = N Cols( captureMatrix ), i >= 1, i--,
					If( captureMatrix[i] != 0,
						Break(),
						captureMatrix[i] = .
					)
				);*/
				if( Row() == N Rows( dt ), zerocounter++ );
				value = Mean( captureMatrix[ 1:: ncols(captureMatrix) - (zeroCounter - 1)] );
				flag = 0;
				zeroCounter = 0;
				captureMatrix = [];
			);
		);
		value;
	)
);
Jim
jojmp
Level III

Re: How to find the average of samples at random intervals?

The first script gives the correct answer but the output of both the scripts are not same, why have you commented some part of the code

txnelson
Super User

Re: How to find the average of samples at random intervals?

The second version of the code is more efficient. Given the amount of data you are running I thought it would help.  It should provide the same results.  If it does not, you can try just removing all of the Show() statements from the first version of the code, and if that works.

Jim