Function index (MATLAB)
/src
rs_addtree_choicedata(data_comp, aux)
[ad,aux_out]=rs_addtree_choicedata(data_comp,aux) analyzes a set of triadic choices to determine the addtree index (a measures of consistency with the four-point inequality, a necessary condition for distances to be consistent with an additive tree). Thi is described in Ordinal Characterization of Similarity Judgments on arXiv and Mathematical Neuroscience and Applications
The analysis is carried out for a range of criteria for the triads to include, and for Dirichlet fits to the choice probability distribution based on all triads (in 'ad.global'), or only the triads that meet threshold criteria (in 'ad.private'). See note below regarding threshold criteria and global vs. private analyses.
Input arguments:
-
data_comp(int 2-D array) –Triadic choice data, with each row containing the data from a single kind of comparison
- col 1 is reference, col 2 is s1, col 3 is s2
- col 4: number of times the first difference was judged more similar than the second difference
- col 5: number of times the comparison was made
-
aux(struct) –a structure, can be omitted, with fields
opts_addtree(struct) – options for analysis, with fieldsif_log(int) – 1 to log progress, 0 to omit; default is 1h_fixlist(float 1-D array) – values for discrete component 'h', should include zero and be in ascending order, default is [0 0.001 0.01 0.1]ntriplets_min(int) – minimum number of triplets for an analysis, default is 3ntents_min(int) – minimum number of tents for an analysis, default is 3if_private(int) – 1 to also do calculations with Dirichlet fits only to the triads that meet threshold criteria, 0 to omit; default is 0if_frozen(int) – random number control; 1 for same numbers every run, 0 for different random numbers each run, negative integer for a fixed seed each run, default is 1a_limits(float) – allowed range for 'a' (shape), when fitting only 'a', default is [10^-2 10^2]a_optimset(struct) – non-default optimizations parameters for fitting 'a', withfminbnd, default is struct()ah_optimset(struct) – non-default optimizations parameters for fitting 'a' and 'h', withfminsearch, default is struct()if_fast(int) – use hard-coding for partitions, skip calls to filldefault, default is 1if_check(int) – 1 to compare methods, -1 to log, treated as 0 if if_fast=1, default is 0tol(float) – tolerance for checking consistency, ignored if if_check is 0, default is 10^-5if_vec(int) – if present, use vectorized method, default is abesentif_partition(struct) – if present, use general calculation of psg_ineq_logic, default is absent
Plotting and replotting
Options for statistics and shuffles
Options to control optimization details
Options for internal use and maintenance
opts_check(struct) – options for consistency checking, with fieldif_warn(int) – 1 to show warnings, 0 to suppress; default is 1
Output arguments:
-
ad(struct) –analysis results, a structure with fields
summary(cell 1-D array) – summary of addtree index, organized of by fraction of triplets retained; summary{1} is analysis with fixed value of 'h', summary{2} is analysis with 'h' fitted; summary{:}.adt contain the following subfieldsparams(struct) – params.a and params.h are the Dirichlet parametersapriori_vals(float) – a priori value of the indexah_llr(float) – log likelihood ratio for the Dirichlet fit to the choice probability distributionthr_type(cell 1-D array) – statistics for threshold type 1 (min), 2 (max), 3 (avg)tally_table(int 2-D array) – tally_table(ithr,[1 2 3]) is the threshold, count of triads, count of trialsmeans_per_set_adj(float 2-D array) – means_per_set_adj(ithr,[1 2 3]) is the mean index for each threshold typeeb_stds(float 2-D array) – 1 s.d. error bar sizefrac_keep_list(float 1-d array) – fraction of triplets to keepthr_ptr_use(int 1-D array) – pointers into thresholds (tally_table(:,1)), corresponding to values in frac_keep_list
global(struct) – detailed analysis for addtree index, based on Dirichlet fits to choice probabilities for all triadic judgments, with fieldsa(int 3-D array) – a(1,1:2,ih) is the fitted Dirichlet shape parameter 'a' and log likelihood per trial assuming h=h_fixlist(ih)ah(int 2-D array) – ah(1,1:3) are the jointly fitted Dirichlet parameters 'a' and 'h' and log likelihood per trial for threshold value dirichlet.tallies(ithr,1)adt_hfixed(cell 2-D array) – adt_hfixed{isv,ithr_type}(ithr,:,ih) is the sum (isv=1) or the variance (isv=2) of the addtree index, for threshold type ithr_type, threshold value dirichlet.tallies(ithr,1), assuming h=h_fixlist(ih)adt(cell 2-D array) – adt{isv,ithr_type}(ithr,:) is the sum (isv=1) or the variance (isv=2) of the addtree index, for threshold type ithr_type, threshold value dirichlet.tallies(ithr,1), with 'a' and 'h' jointly fitted
private(struct) – detailed analysis for addtree index, based on Dirichlet fits only to choice probabilities that meet the threshold criterion, with fieldsa(cell 1-D array) – a{ithr_type}(ithr,1:2,ih) are the fitted Dirichlet shape parameter 'a' and log likelihood per trial for threshold type and threshold value dirichlet.tallies(ithr,1), assuming h=h_fixlist(ih)ah(cell 1-D array) – ah{ithr_type}(ithr,1:3,ih) are the jointly fitted Dirichlet parameters 'a' and 'h' and log likelihood per trial for threshold type ithr_type and threshold value dirichlet.tallies(ithr,1)adt_hfixed(cell 2-D array) – adt_hfixed{isv,ithr_type}(ithr,:,ih) is the sum (isv=1) or the variance (isv=2) of the addtree index, for threshold type ithr_type, threshold value dirichlet.tallies(ithr,1), assuming h=h_fixlist(ih)adt(cell 2-D array) – adt{isv,ithr_type}(ithr,:) is the sum (isv=1) or the variance (isv=2) of the addtree index, for threshold type ithr_type, threshold value dirichlet.tallies(ithr,1), with 'a' and 'h' jointly fitted
dirichlet(struct) – Dirichlet fits for lowest and highest thresholds for number of trials in a triad, with fieldstallies(int 2-D array) – tallies(:,1) is threshold number of trials in a triad; tallies(:,2) is number of triads meeting the threshold; tallies(:,3) is number of trials in those triadscolumns_tallies(cell 1-D array) – labels for columns of talliesh_fixlist(float 1-D array) – list of values assumed for the discrete component, first element is 0a(int 3-D array) – a(ithr,1,ih) is fitted value of Dirichlet shape parameter 'a' for triads meeting threshold of tallies(ithr,1) and assuming h=h_fixlist(ih); a(ithr,2,ih) is corresponding log likelihood per trialcolumns_a(cell 1-D array) – labels for columns of aah(int 2-D array) – ah(ithr,1:2) are jointly fitted values of Dirichlet shape parameter 'a' and discrete parameter 'h' for triads meeting threshold of tallies(ithr,1); ah(ithr,3) is corresponding log likelihoood per trialcolumns_ah(cell 1-D array) – labels for columns of ah
meta(struct) – labels for dimensions of the variables in ad.global and ad.privatecounts(struct) – summary of the input data, a structure with fieldsntrials_found(int) – number of individual judgmentsntriads_found(int) – number of distinct triads judgednstims_found(int) – number of different stimuliunique_stims(int 1-D array) – list of unique stimuli
tallies(cell 1-D array) – summary of the data used for each calculation in global and private, where tallies{ithr_type}(ithr,:) is [threshold pointer, number of triplets used, number of trials used] for threshold type ithr_type (1: min, 2: max, 3: avg, see note below regarding thresholds); the threshold value corresponding to ithr is dirichlet.tallies(ithr,1)
Addtree indices
Dirichlet fits
-
aux_out(struct) –auxiliary outputs and parameter values used, with fields
warnings(char) – warnings generated during consistency checkwarn_bad(int) – number of warnings that prevent further processingopts_addtree(struct) – aux,opts_addtree with defaults and values usedopts_check(struct) – aux.opts_check, with defaults filled inopts_dirfit_a(struct) – options used forrs_dirfit_choicedatafor fitting Dirichlet parameter 'a'opts_dirfit_ah(struct) – options used forrs_dirfit_choicedatafor fitting Dirichlet parameters 'a' and 'h'opts_triplike(struct) – options used forpsg_umi_triplikefig_handles(cell 1-D array) – handles to figures for summary plot ((present only if if_plot>=1)fig_handle_detailed(handle) – handle to figure for detailed plot (present only if if_plot=2)
Note regarding thresholds and global vs. private analyses
- Triplets are screened by a threshold criterion based on the number of trials before inclusion in the calculation of the symmetry and ultrametric indices.
- The criterion is applied three ways: to the minimum numnber of trials of the three triads in a triplet, the maximum number, and the average number
- For the 'global' analysis, the selected triplets are used to calculate the symmetry and ultrametric indices, but all triads are used to calculate the Dirichlet parameters
- For the 'private' analysis, the selected triplets are used to calculate the symmetry and ultrametric indices and also to calculate the Dirichlet parameters
- The 'private' analysis is substantially slower than the 'global' analysis, and values are of the indices are typically similar; it is only enabled by setting opts_addtree.if_private=1
Triads, trials, triplets, and tents
- A triad is a set of three stimuli used in a triadic judgment: one stimulus is the reference, and the other two are the comparison stimuli
- A trial is a single judgment of similarity for a given triad
- A triplet is a set of three triads built out of the same three stimuli, in which each stimulus in turn serves as the reference
- The number of trials in a triplet is the sum of the number of trials in its three triads
- A tent is a set of six triads built out of four stimuli. Three of the triads are a triplet built from the first three stimuil; the other three triads are triads built from the fourth stimulus and two of the first three.
See also: rs_dirfit_choicedata, rs_symumi_choicedata, PSG_TRIPLET_CHOICES, loglik_beta_discrete.
Source code in src/rs_addtree_choicedata.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 | |
rs_align_coordsets(data_in, aux)
[data_out,aux_out]=rs_align_coordsets(data_in,aux)
aligns a dataset structure with partially overlapping stimuli
Each of the records in the dataset structure data_in contains the responses to one or more stimuli,
with stimulus identity in record k determined by the strings in data_in.sas{k}.typenames. The stimuli
in each of the records may differ, and may overlap.
Each of the corresponding records in the dataset structure data_out has a stimulus set
equal to the union of all of the stimulus sets in the records of data_in. For a stimulus in the kth record of
data_out for which there is no entry in data_in, the coordinates are NaN. See note below regarding stimulus coordinates.
The stimulus labels in data_out.sas{k}.typenames are in alphabetical order, and are identical for all of the records
Thus, even if there is complete overlap between the stimuli in data_in, the dataset structure data_out may differ.
The stimulus coordinates in data_out.sas{k} are correspondingy aligned; see note below regarding stimulus coordinates.
Input arguments:
-
data_in(struct) –dataset structureto be aligned containing n records, with fieldsds(cell array) –coordinate structure, ds{k}{idim} is an array of [nstims idim] of coordinates for the kth recordsas(cell array) –stimulus metadata structure, sas{k} is the stimulus metadata for the kth recordsets(cell array) –set metadata structure, sets{k} is the response metadata for the kth record
-
aux(struct) –auxiliary options, may be omitted, with fields
opts_align(struct) – options for alignment and consistency checking, with fieldsif_log(int) – 1 to log progress, 0 to suppress; default is 1min(int or char) – minimum number of datasets that must contain a stimulus, in order for the stimulus to be included in data_out; default is 1, equivalent to 'any'; can also be 'all', meaning that stimuli must be present in all datasets to be included in data_outif_type_coords_remake(int) – controls alignment of stimulus coordinates, typically omitted or set to [], see note below regarding stimulus coordinatesif_btcremz(int) – typically omitted, defaults to 1, see note below regarding labels for binary texture coordinates
opts_check(struct) – options for consistency checking, with fieldif_warn(int) – 1 to show warnings when datasets are checked for consistency, 0 to suppress; default is 1
opts_rays(struct) – options for rays, typically omitted; see note below regarding rays
Output arguments:
-
data_out(struct) –aligned
dataset structurewith n records, same format as asdata_in -
aux_out(struct) –auxiliary outputs and parameter values used, with fields
warnings(char) – warnings generated during consistency checkwarn_bad(int) – number of warnings that prevent further processingopts_align(struct) – aux.opts_align, with defaults filled in, and alsoovlp_array_all(integer array) – the overlap array for the pooled dataset. Each row corresponds to one of the typenames (see sa_pooled below) contained in any of the input records; ovlp_array_all(s,k)=1 if the stmulus is present in record k ofdata_in
opts_check(struct) – aux.opts_check, with defaults filled inopts_import(struct) – aux.opts_import, with defaults filled inopts_rays(cell array) – opts_rays{k} is a structure which contains the options used for creating rays in record k indata_outovlp_array(int 2-D array) – ovlp_array(s,k)=1 if the stimulus data_out.sets{:}.typenames{s} is present in record k ofdata_in, 0 otherwisesa_pooled(struct) – thestimulus metadata structurefor the pooled stimulus set; see note below regarding stimulus coordinatesrayss(cell array of struct) – rayss{k} is theray structurefor record k indata_out; see note below regarding raysopts_btcremz(cell array of struct) – see note below regarding labels for binary texture coordinates
General notes
- For all records with data_in.sets{k}.type='data', the strings in data_in.sets{k}.paradigm_type must agree.
- Pipeline: data_out.sets{k}.pipeline.sets{1} contains metadata for the kth record of
data_in; data_out.sets{k}.pipeline.sets_combined{:} contains metadata from all records ofdata_in; data_out.sets{1}.pipeline.type='align'.
Note regarding stimulus coordinates
-
Stimulus coordinates are optionally present in data_in.sas{k} in the fields type_coords, btc_specoords, or btc_augcoords. Their treatment is governed by aux.opts_align.if_type_coords_remake. If this field is omitted or [], behavior is determined by the stimulus coordinates supplied in data_in.sas{k}. A value of 0 attempts to merge the coordinates, a value of 1 does not.
-
Merging (if_type_coords_remake=0, or, stimulus coordinates are not all 0 or 1, or a non-square array with at least 2 columns): In the aligned
stimulus metadata structuredata_out.sas{k}, if the stimulus typename is not present in data_in.sas{k}, stimulus coordinates are NaN. In the pooledstimulus metadata structureaux_out.sa_pooled, stimulus coordinates are taken from the first occurence of the typename in data_in.sas{:} is used. A similar behavior is applied to other subfields of the stimulus metadata structure that relate to individual stimuli. These fields are listed in aux_out.opts_align.fields_align, which defaults in psg_align_coordsets to {'specs' 'spec_labels' 'btc_augcoords' 'btc_specoords' 'type_coords'} -
No merging (if_type_coords_remake=1, or stimulus coordinates absent, or, stimulus coordinates do not meet above requirements): In the aligned
stimulus metadata structuredata_out.sas{k}, dummy coordinates are created in one of the fields type_coords, btc_specoords, or btc_augcoords (the field chosen is determined by the first of that list that is found in data_in.sas{:}). The dummy coordinates can be an empty matrix, zeros, ones, or the identity, as determined by aux.opts_import.type_coords_def. This defaults to 'none', can be 'zeros','ones', or 'eye', and the value used is reported in aux_out.opts_import.type_coords_def and aux_out.opts_align.type_coords_def. -
The behavior taken is reported in aux_out.opts_align.if_type_coords_remake.
Note regarding rays
- The
ray structuredescribes relationships among the simulus coordinates:rays, i.e., sets of stimuli that lie along an axis or a ray from the origin,rings, stimuli that lie at an approximately equal distance from the origin, and nearest neighbors. It is only created if there is a valid set of stimulus coordinates.
Note regarding labels for binary texture coordinates
- if_btcremz is only relevant for
binary texture domainmetadata, and controls whether an attempt should be made to simplify fields sas{k}.spec_labels and sas{k}.typenames prior to matching and alignmnent. If 1 (default), coordinates that are specified as zero are removed, provided that this does not change the stimulus after maximum-entropy extension. For example, in data_in.sas{k}.spec_labels, 'b=-0.00 c=-0.40' becomes 'c=-0.40' the corresponding entry in data_in.sas{k}.typenames, 'bm0000cm0400' becomes 'cm0400'. An all-zero coordinate becomes 'rand'. Results for simplification of record k are returned in opts_btcremz{k}.
See also
rs_aux_customize, rs_findrays, PSG_ALIGN_COORDSETS, rs_import_coordsets, PSG_COORD_PIPE_UTIL, PSG_BTCREMZ, rs_check_coordsets.
Source code in src/rs_align_coordsets.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
rs_aux_customize(aux, caller, aux_default_filename)
aux_out=rs_aux_customize(aux,caller,aux_default_filename) sets the auxiliary inputs to customized defaults
This read a file created by rs_aux_defaults_define at the time of installation, and should be edited to customize the default auxiliary inputs as needed.
Input arguments:
-
aux(struct) –options structure, typically with subfields with names like opts_read, opts_disp, opts_knit, etc.
-
caller(char) –name of calling function, e.g., 'rs_get_coordsets'; may be empty
-
aux_default_filename(char) –full path to the file created by
rs_aux_defaults_define; defaults to 'rs_aux_defaults.mat'
Output arguments:
-
aux_out(struct) –aux, with defaults filled in
Default assignment precedence
- First priority to value explicitly provided in a function call
- Then, value specified in an rs_*.m module via a 'filldefault' statement
- Then, value listed in the specific.(caller) section of
rs_aux_defaults_define - Then, value listed in the generic section of
rs_aux_defaults_define
See also: rs_aux_defaults_define, rs_aux_force.
Source code in src/rs_aux_customize.m
rs_aux_force(aux_name, caller, aux_force_filename, aux_default_filename)
[opts_forced,def,force]=rs_aux_force(aux_name,caller,aux_force_filename,aux_default_filename) sets an options structure to override user-customized defaults
This module is solely intended for use during benchmarking with the rs_*test modules.
Input arguments:
-
aux_name(char) –name of an options structure, e.g., opts_read, opts_disp
-
caller(char) –name of calling function, e.g., 'rs_get_coordsets'; may be empty
-
aux_force_filename(char) –full path to the overriding set of default auxiliary inputs
-
aux_default_filename(char) –full path to the default auxiliary input file created by
rs_aux_defaults_define; defaults to 'rs_aux_defaults.mat'
Output arguments:
-
opts_forced(struct) –structure whose fields in aux_force_filename differ from those in aux_default_filename
-
def(struct) –auxiliary inputs from aux_default_filename
-
force(struct) –auxiliary inputs from aux_force_filename
See also: rs_aux_defaults_define, rs_aux_customize.
Source code in src/rs_aux_force.m
rs_check_coordsets(data_in, opts)
[check,opts_used]=rs_check_coordsets(data_in,opts) checks the consistency of dataset structures between and within records,
and tallies the available dimensions and stimuli
Input arguments:
-
data_in(struct) –dataset structure, with fieldsds(cell array) –coordinate structure, ds{k}{idim} is an array of [nstims idim] of coordinates for the kth recordsas(cell array) –stimulus metadata structure, sas{k} is the stimulus metadata for the kth recordsets(cell array) –set metadata structure, sets{k} is the response metadata for the kth record
-
opts(struct) –auxiliary options, may be omitted, with fields
if_warn(int) – 1 to display warnings, 0 to omit; default is 0if_checkorder(int) – 1 to check that the order of the stimuli, as listed in ds.sas{k}.typenames, is the same, 0 to compare independent of odrer; default is 0record_num_offset(int) – value to add to the record number in displaying aarnings; default is 0
Output arguments:
-
check(struct) –summary of the consistency check, with fields
warnings(char) – warning messageswarn_bad(int) – count of severe warnings that likely prevent processingnsets(int) – number of recordsnstims_each(int 1-D array) – nstims_each(k) is the number of stimuli in record kdim_list_each(cell array) – dim_list_each{k} is the list of dimensions available in record kdim_list_union(int 1-D array) – union of dim_list_each{:}dim_list_inter(int 1-D array) – intersection of dim_list_each{:}typenames_each(cell array) – typenames_each{k} is data_in.sas{k}.typenames, in original ordertypenames_union(cell array) – union of typenames_each{:}, alphabetizedtypenames_inter(cell array) – intersection of typenames_each{:}, alphabetized
-
opts_used(struct) –opts, with defaults filled in
See also: rs_knit_coordsets, rs_align_coordsets.
Source code in src/rs_check_coordsets.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
rs_concat_coordsets(data_in1, data_in2, aux)
[data_out,aux_out]=rs_concat_coordsets(data_in1,data_in2,aux)
concatenates two dataset structures and checks the concatenated dataset structure for consistency
Input arguments:
-
data_in1(struct) –first
dataset structure, containing \(n_1\) records, with fieldsds(cell array) –coordinate structure, ds{k}{idim} is an array of [nstims idim] of coordinates for the kth recordsas(cell array) –stimulus metadata structure, sas{k} is the stimulus metadata for the kth recordsets(cell array) –set metadata structure, sets{k} is the response metadata for the kth record
-
data_in2(struct) –second
dataset structure, containing \(n_2\) records, same format asdata_in1 -
aux(struct) –
Output arguments:
-
data_out(struct) –concatenated
dataset structurewith \(n_1 + n_2\) records, same format as asdata_in1 -
aux_out(struct) –
Notes
- aux may be omitted; defaults are filled in.
data_in1anddata_in2are typically created byrs_get_coordsets,rs_align_coordsets, orrs_import_coordsets.- data_out.sets{k}.pipeline is copied from data_in1 or data_in2 and is not updated.
Source code in src/rs_concat_coordsets.m
rs_dirfit_choicedata(choices, aux)
[dirfit,aux_out]=rs_dirfit_choicedata(choices,aux) finds the maximum-likelihood fit of a symmetric Dirichlet distribution to choice probabilities, optionally including a discrete component at p=0.5
Input arguments:
-
choices(int 2-D array) –choices(:,1) is the number of times the first difference was judged more similar than the second difference; choices(:,2) is the number of times the comparison was made; this is typically the last two columns of data_comp as returned by
rs_read_choicedata -
aux(struct) –a structure, can be omitted, with fields
opts_dirfit(struct) – options for fitting Dirichlet parameters, can be omitted, with fieldsif_log(int) – 1 to log progress, 0 to omit; default is 1if_fit_a(int) – 1 to fit the shape parameter ('a') with an assumed value of the discrete parameter, 0 omits, default is 1fixed_h(float) – value of 'h' to use for fitting just 'a', default is 0, which corresponds to zero weight for the discrete partif_fit_h(int) – 1 to fit the discrete parameter ('h') with an assumed value of the shape parameter 'a', 0 omits, default is 0fixed_a(float) – value of 'a' to use for fitting 'h', default is 1, which corresponds to a flat distributionif_fit_ah(int) – 1 to fit the shape parameter 'a' and the discrete parameter 'h' simultaneously, 0 omits, default is 0; see note belowif_stats(int) – 1 to compute jackknife standard error of measurement, 0 does not; default is 0if_frozen(int) – random number control; 1 for same numbers every run, 0 for different random numbers each run, negative integer for a fixed seed each run, default is 1njacks_max(int) – maximum number of choice probabilities to remove for jackknifing (ignored if if_stats=0), default is 500a_limits(float) – allowed range for 'a' (shape), when fitting only 'a', default is [10^-2 10^2]h_limits(float) – allowed range for 'h' (discrete weight) when fitting only 'h', default is [0 1]a_optimset(struct) – non-default optimizations parameters for fitting 'a', withfminbnd, default is struct()h_optimset(struct) – non-default optimizations parameters for fitting 'h', withfminbnd, default is struct()ah_optimset(struct) – non-default optimizations parameters for fitting 'a' and 'h', withfminsearch, default is struct()
Options for statistics and shuffles
Options to control optimization details
opts_check(struct) – options for consistency checking, with fieldif_warn(int) – 1 to show warnings, 0 to suppress; default is 1
Output arguments:
-
dirfit(struct) –the fitted Dirichlet parameter values, a structure with fields
nchoices(int) – number of choices used in the analysis, i.e., the number of rows of choices that has a nonzero element in the final columna(struct) – analysis of the Dirichlet shape parameter 'a' (present only if if_fit_a=1), with fieldsval(float) – maximum-likelihood value for allnat_per_choice(float) – log likelihood (natural log) per choice probabilityllnat_per_trial(float) – log likelihood (natural log) per trialexitflag(int) – exit flag fromfminbndoptimizationoutput(struct) – detailed output fromfminbndoptimizationoptimset(struct) – optimization options used infminbndoptimizationjack_val(float 1-D array) – maximum-likelihood value for 'a' for each jackknife, only present if if_stats=1jack_llnat_per_choice(float 1-D array) – log likelihood (natural log) per choice probability for each jackknife, only present if if_stats=1jack_sem(float) – jackknife standard error of measurement for a, only present if if_stats=1fixed_h(float) – value of 'h' used for fitting just 'a'
h(struct) – analysis of the Dirichlet shape parameter 'h' (present only if if_fit_h=1), with fieldsval(float) – maximum-likelihood value for allnat_per_choice(float) – log likelihood (natural log) per choice probabilityllnat_per_trial(float) – log likelihood (natural log) per trialexitflag(int) – exit flag fromfminbndoptimizationoutput(struct) – detailed output fromfminbndoptimizationoptimset(struct) – optimization options used infminbndoptimizationjack_val(float 1-D array) – maximum-likelihood value for 'h' for each jackknife, only present if if_stats=1jack_llnat_per_choice(float 1-D array) – log likelihood (natural log) per choice probability for each jackknife, only present if if_stats=1jack_sem(float) – jackknife standard error of measurement for 'h', only present if if_stats=1fixed_a(float) – value of 'a' used for fitting just 'h'
ah(struct) – joint analysis of the shape parameter and discrete parameter (present only if if_fit_ah=1), with fieldsval(float 1-D array) – val(1) is maximum-likelihood value for a, val(2) is maximum-likelihood value for hll_per_choice(float) – log likelihood per choice probabilityllnat_per_trial(float) – log likelihood (natural log) per trialexitflag(int) – exit flag from `fminsearch optimizationoutput(struct) – detailed output fromfminsearchoptimizationoptimset(struct) – optimization options used infminsearchoptimizationjack_val(float 2-D array) – maximum-likelihood value for a (jack_val(1,:)) and h (jack_val(2,:) for each jackknife, only present if if_stats=1jack_llnat_per_choice(float 1-D array) – log likelihood (natural log) per choice probability for each jackknife, only present if if_stats=1jack_sem(float 1-D array) – jack_sem(1) is jackknife standard error of measurement for a, jack_sem(2) is jackknife standard error of measurement for h, only present if if_stats=1
jack_select(int 1-D array) – list of choices omitted on each jackknife (empty if if_stats=0)
-
aux_out(struct) –auxiliary outputs and parameter values used, with fields
Notes re fitting, log likelihoods and statistics
-
The distribution of observed probabiliies p is fitted to a symmetric Dirichlet distribution with parameter 'a', i.e., P(p)=(p^(a-1))((1-p)^(a-1))/B(a-1,a-1), where B is the beta function
- Each nonzero row of 'choices' is considered an independent observation of the chioce probability distribution; rows containing zeros are ignored
- If if_fit_ah=1, it is also fitted to a symmetric Dirichlet distribution mixed with a discrete component at p=0.5, with weights 1-h and h, respectively
-
Log likelihoods use natural logs, and are normalized by the number of nonzero rows of 'choices'
-
Minimal number of choice probabilities (nonzero rows of 'choices') needed
- At least 2 choice probabilities are needed to fit the symmetric Dirichlet distribution
- At least 3 choice probabilities are needed to fit the distribution with an additional discrete component
- For a jacknife estimate of the s.e.m., at least one additional choice probability is needed
- If all empirical choice probabilities are 0 or 1, the estimated parameter values will go to the limits allowed for the fitted parameters, 'a_limits' and 'h_limits'
- This is a bare minimum for non-degeneracy. Useful fits typically require many more choice probabilities.
-
Optimization behavior can be controlled by aux.opts_dirfit.a_optimset and aux.opts_dirfit.ah_optimset. For example, to displahy each iteration for fitting 'a', set aux.opts_dirfit.a_optimset.Display='iter';
See also: rs_read_choicedata, loglik_beta_discrete, FMINSEARCH, FMINBND.
Source code in src/rs_dirfit_choicedata.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
rs_disp_coordsets(data_in, aux)
aux_out=rs_disp_coordsets(data_in,aux) displays one or more views of pairs or triplets of coordinates in a dataset structure
Multiple views can be plotted, one eachin a subplot of the same figure. This is particularly helpful if the dimensionality of the coordinates is high: each subplot could show a different combination of two or three coordinates. Plots of two coordinates will produce a planar view; plots of three coordinates will produce an isometric 3D view. Subplots are left in the 'hold on' state.
Input arguments:
-
data_in(struct) –dataset structureto be processed, with fieldsds(cell array) –coordinate structure, ds{k}{idim} is an array of [nstims idim] of coordinates for the kth recordsas(cell array) –stimulus metadata structure, sas{k} is the stimulus metadata for the kth recordsets(cell array) –set metadata structure, sets{k} is the response metadata for the kth record
-
aux(struct) –auxiliary inputs, may be omitted, with fields
opts_disp(struct) – options for display, with fields to contolset_select(int 1-D array) – list of records to show; defaults is [1:length(data_in.ds)]dim_select(int) – dimension to show (>=2); i.e., dim_select=k results in display of the coordinates in data_in.ds{set_select}{k}; default is 3 unless only two dimensions are available; must be at least 2coord_group_size(int) – number of coordinates to display together, in range [2 3]; default is min(dim_select,number of dimensions available,3)coord_group_method(char) – method of selecting coordinates- 'all': (default) plot all combinations
- 'keeplow': keep 1 to dim_select-1 and step the highest; [dim_select,coord_group_size]=[5,3] yields [1 2 3],[1 2 4],[1 2 5]
- 'keepone': keep one dimension and step the rest; [dim_select,coord_group_size]=[5,3] yields [1 2 3],[1 2 4],[1 2 5],[1 3 4],[1 3 5],[1 4 5]
- 'rolling': rolling contiguous subsets; [dim_select,coord_group_size]=[5,3] yields [1 2 3],[2 3 4],[3 4 5],[4 5 1],[5 1 2]
- 'onlylowest': only the lowest dimensions; [dim_select,coord_group_size]=[5,3] yields [1 2 3]
- 'list': specify a list in opts_disp.coord_groups, as an array with coord_group_size columns, e.g., opts_disp.coord_groups=[1 2 3;1 4 5;1 6 7] creates three subplots, with coordinates {1,2,3} in the first, {1,4,5} in the second, {1,6,7} in the third
coord_groups(int 2-D array) – groups of coordinates to show together if coord_group_method='list', as rows (of length coord_group_size) of an integer array; each row will generate one subplotdata_show_method(char) – which data points to show, options are 'all', 'none', 'first', 'last', 'list'; default is 'all'data_show_list(int 1-D array) – list of data points to show, if data_show_method='list'; points plotted are data_in.ds{set_select}{k}(data_show_list,:); This applies to data in all records. To disable display of individual data points in specific records, set their coordinates to NaN.fig_handle(handle) – handle to figure; will be created if empty or not providedfig_position(int 1-D array) – position parameters [left bottom width height] for figure to be created; see note below regarding customizationfig_name(char) – title for figure; default is dimension shownaxis_handles(cell array of handles) – handle to axes, one for each subplot, will be created empty or not providedset_labels(char or cell array of char) – labels for each record that will appear in legend; defaults is 'set 1', etc.; cannot be empty; see note regarding plot formattingdata_label_setsel_method(char) – selects which records to label individual points, options are 'all','none', 'first' , 'last', or 'list'; default is 'first'; note that 'all','first', and 'last' apply to the records showndata_label_setsel_list(int 1-D array) – list of datasets to label, if data_label_setsel_method='list'data_label_method(char) – selects which data points to label, options are 'all', 'none', 'first', 'last', 'list'; default is 'all'; labels are taken from data_in.sas{k}.typenames; note that 'all','first',and 'last' refer to data points showndata_label_list(int 1-D array) – list of data points to label, if data_label_method='list'data_label_font_size(int) – font size for data labels, default is axis_font_sizedata_label_interpreter(char) – interpreter for labeling data, [] (default) uses system default, alternatively 'none','tex','latex'data_label_typenames_vary(int) – 1 to allow typenames to vary across datasets, 0 does not; default is 0callout_amount(float) – moves the position of a label away from the data point, specified in units of rms deviation of data from callout_center; default is 0callout_colors(cell array of color specifiers) – color for callout lines connecting labels and points; default is {'k'}; can also be 'set_colors' to match set_colorscallout_linestyles(cell array of char) – line styles for above callout lines; default is {'-.'}callout_linewidths(int 1-D array) – line widths for above callout lines; default is 1callout_center(char or int 1-D array) – callout lines point from the specified location outward; default is 'centroid' (centroid of data), can also be 'zero' or a coordinate value, of length 'dim_select'axis_font_size(int) – font size for axis; default is 8; see note below re customizationaxis_label_font_size(char) – font size for axis labels; default is axis_font_sizeaxis_label_prefix(char) – prefix for axis label, default is 'coord'; see note below regarding customizationaxis_labels(cell array of char) – cell array of strings, cycled through if necessary, with text for axis labels. If empty, then axis labels are genrated from axis_label_prefixaxis_view(int or float 1-D array or cell array) – 3-D view descriptor, default is 3 (standard 3-d view), 2 is 2-d view; can also be azimuth-elevation pair; standard 3-d view is [-37.5 30]; can be also be cell array of view specifiers, is cycled through for each subplotaxis_equal(int) – 1 to set axes to have equal scales, 0 autoscales; default is 1axis_range(char) – 'tight' to set axis range to limits of data, 'auto' for autoscaling, or 'list' to specify by axis_range_list; default is 'tight'axis_range_list(float 2-D array) – axis range specification, as rows of [low, high] values, one for each coordinate plotted; cycled through by rows if necessaryset_colors(color specifier or cell array of color specifiers) – color assigned to each record; default is {'k','b','c','m','r',[0.5 0.5 0],'g'}; elements can be any valid color specifier; see note regarding plot formattingset_markers(char or cell array of char) – marker for each record; defaults is {'.'}; see note below regarding plot formattingset_markersizes(int 1-D array) – marker size for each record; default is 8; see below note regarding plot formattingset_filled(int 1-D array) – 1 for records in which markers are filled, 0 for unfilled if possible; default is 0; note that only some marker, e.g., o,s,h,p can be unfilledset_colors_filled(color specifer or cell array of color specifiers) – color for inside of filled symbols for each record, ignored if set_filled=0; default is set_colorsset_alphas(float 1-D array) – alpha blending for each record, default is 1 (opaque); note that alpha-blending (transparency) may not be availble on all systemsconnect_data_method(char) – which pairs of data points to connect within a record; default is 'none'; options refer to the points selected for display by 'data_show_method'; see note below regarding plot formatting- 'none': no connections between points
- 'all': connect all pairs of points
- 'star' or 'star_first': connect all points to first
- 'star_last': connect all points to last
- 'chain': connect first point =to second, second point to third, ..., and next-to-last point to last point
- 'circuit': same as 'chain' but adds a connection from last point to first
- 'list': specify the pairs of points in connect_data_list
connect_data_list(int 2-D array) – two-column array of data points to connect (if connect_data_method='list')connect_data_linestyles(char or cell array of char) – line styles assigned to connections within each record, default is 'none' (disconnected)connect_data_linewidths(int 1-D array) – line widths for connections within each record; default is 1connect_sets_method(char) – which records to connect; default is 'none'; options refer to the records selected for display by 'set_select'; see note below regarding plot formatting- 'none': no connections between data from different records
- 'all': connect all pairs of records
- 'star' or 'star_first': connect all records to first
- 'star_last': connect all records to last
- 'chain': connect first record to second, second record to third, ..., and next-to-last record to last record
- 'circuit': same as 'chain' but adds a connection from last record to first
- 'list': specify the pairs of records in connect_sets_list
connect_sets_list(int 2-D array) – two-column array of records to connect, used if connect_sets_method='list'connect_sets_data_method(char) – selects the data points to connect between records: any of the options for data_label_method or 'labeled', which connects all data points designated by 'data_label_method'; default is 'all'connect_sets_data_list(int 1-D array) – data points to connect between records, if connect_sets_data_method='list'connect_sets_color_mode(char) – specifies how the connecting semgent between records is colored; default is 'split'- 'first': use color of first record in connected pair
- 'last': use color of last record in connected pair
- 'split': first half of segment matches first record in connected pair; second half of segmentmatches second record in connected pair
- 'list': specify colors in connect_sets_colors
connect_sets_colors(color specifier or cell array of color specifiers) – if connect_sets_color_mode='list';, these are the colors for for connecting segments; cycled through if necessaryconnect_sets_linestyles(char or cell array of char) – line styles assigned to connections between records; default is '-' (solid); cycled through if necessaryconnect_sets_linewidths(int 1-D array) – line widths assigned to connections between records; default is 1; cycled through if necessaryset_offsets(float 2-D array or char) – this allows the data in each record to be offset to avoid overlap; default is no offset; specified by 0- if an array, each row, of length dim_select (which wll be truncated or padded as needed) specifies the offset for the corresponding record in
data_in - 'margin_amount' puts a margin of set_offsets_margin_amount between each dataset and the next
- 'margin_fraction' puts a fractional margin of set_offsets_margin_fraction * average span of adjacent sets
- if an array, each row, of length dim_select (which wll be truncated or padded as needed) specifies the offset for the corresponding record in
set_offsets_margin_amount(float 1-D array) – absolute margin between datasets if set_offsets='margin_amount; defaults to ones(1,dim_select); can be 0 or negative, truncated or padded to dim_selectset_offsets_margin_fraction(float 1-D array) – fractional margin between datasets if set_offsets='margin_fraction; defaults to zeros(1,dim_select); can be 0 or negative, truncated or padded to dim_selectset_offsets_coordchoices(int or char or cell array of char) – if set_offsets='margin_amount' or 'margin_fraction', this specifies which coordinate is offset; can be 'first','last','all', or a subset of [1:dim_select]; can also be a cell array of subsetsperp_data_dims(int or int 1-D array) – 1 to drop perpendiculars along that dimension,-1 for perpendicular to top, 0 to omit; default is 0; cycled through if necessaryperp_data_linestyles(char or cell array of char) – line styles for perpendiculars for each record, or 'use_data' to use the style specified by 'connect_data_linestyles' for connecting data points; default is '-' (solid); cycled through if necessaryperp_data_linewidths(int 1-D array) – line widths for perpendiculars for each record; default is 1perp_data_usemarkers(int) – 1 to use markers from original data at foot of perpendicular, 0 for no markers; default is 1if_legend(int) – 1 to include legend, 0 to omit, -1 to omit from all subplots but to create an extra subplot that only has the legend; default is 1legend_font_size(int) – font size for legend; default is axis_font_sizelegend_location(char) – location of legend within plot; any Matlab designator accepted; default is 'Best'legend_interpreter(char) – interpreter for record labels in legend, [] (default) uses system default, alternatively 'none','tex','latex'legend_tags(char) – single string that must be present in a dataset's tag for inclusion in a legend, default is 'set';set_tags(char or cell array of char) – the 'tags' field applied to the plot of each record, for selecting which records appear in legend, default is 'set 1', etc.if_box(int) – 1 to include the bounding box in a 3d plot, 0 to omit; default is 1if_grid(int) – 1 to include the grid, 0 to omit; default is 1if_finalize(int) – 1 to apply view, legend, labels, and perpendiculars, 0 to omit; default is 1
Data selection
Figure and subplot control
Labels
Formatting: axis and views
Formatting: points and lines for each record
Formatting: connections between records
Formatting: positioning
Formatting: perpendiculars from points to walls
Formatting: legend, box, grid
if_warn(int) – 1 to display warnings related to plot configurations, 0 to suppress; default is 1opts_check(struct) – options for consistency checking, with fieldif_warn(int) – 1 to show warnings when datasets are checked for consistency, 0 to suppress; default is 1
Output arguments:
-
aux_out(struct) –auxiliary outputs and parameter values used, with fields
Note regarding customization
- The default figure position can be changed by editing the line containing generic.opts_disp.fig_position in
rs_aux_defaults_define, running it once, and saving the workspace as rs_aux_defaults.mat. - The default font size for axis labels can be changed by editing the line containing generic.opts_disp.axis_font_size in
rs_aux_defaults_define, running it once, and saving the workspace as rs_aux_defaults.mat. - The default prefix for the axis label can be changed by editing the line containing generic.opts_disp.axis_label_prefix in
rs_aux_defaults_define, running it once, and saving the workspace as rs_aux_defaults.mat.
Note regarding plot formatting
- By default, each record is plotted with a different color, a solid dot marker, and no connecting lines.
- These choices can be changed by 'set_colors', 'set_markers', 'set_markersizes', 'set_filled', 'set_colors_filled', 'set_alphas' (but alpha blending may not be availble on all systems).
- The above specifiers can be singletons or cell arrays, and are indexed by the record position in data_in. If there are more records than specifiers, the specifiers are cycled.
- The data points of each record are, by default, not interconnected. This can be changed with the 'connect_data*' options.
- The data points between records are, by default, not interconnected . This can be changed with the 'connect_sets*' options.
See also: rs_disp_enh_coordsets, rs_check_coordsets, rs_get_coordsets, rs_align_coordsets, rs_knit_coordsets, rs_plot_style.
Source code in src/rs_disp_coordsets.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
rs_disp_enh_coordsets(data_in, aux, rays)
aux_out=rs_disp_enh_coordsets(data_in,aux,rays) displayes one or more
views of the coordinates in a dataset structure, with graphical enhancements: connecting stimuli along rays, in rings, and nearest neighbors.
These enhancements depend on the availability of a ray structure, which specifyues rays (stimuli that lie on an approximate straight line from the origin) and
rings (stimuli that lie in a plane at approximately equal distances from the origin), and nearest-neigbhbor pairs.
Input arguments:
-
data_in(struct) –dataset structureto be processed, with fieldsds(cell array) –coordinate structure, ds{k}{idim} is an array of [nstims idim] of coordinates for the kth recordsas(cell array) –stimulus metadata structure, sas{k} is the stimulus metadata for the kth recordsets(cell array) –set metadata structure, sets{k} is the response metadata for the kth record
-
aux(struct) –auxiliary inputs, may be empty, with fields
opts_disp_enh(struct) – options for enhanced display, with fieldsif_points(int) – 1 to display each data point, 0 to suppress; default is 1; see notes below regarding points and raysif_rays(int) – 1 to connect data points along rays, 0 to suppress; default is 1 if 'rays' is non-empty, otherwise 0; see notes below regarding points and raysif_rings(int) – 1 to connect data points in rings, 0 to suppress; default is 1 if 'rays' is non-empty, otherwise 0if_nbrs(int) – 1 to connect nearest-neighbors, 0 to suppress; default is 1 if 'rays' is non-empty, otherwise 0if_nbrs_notsameray(int) – 1 to suppress nearest-neighbor connections if both points are on the same ray, or next to origin; 0 to connect all nearest neighbors; default is 1if_usetypenames(int) – how colors and symbols are determined; 1 (use 'typenames') is default; 0-> determine from stimulus coordinates, a field of data_in.sas{1} (search order: 'type_coords','btc_specoords','btc_augcoords', seers_findraysfor further details)
opts_tn2c(struct) – controls how stimulus labels (data_in.sas{:}.typenames) are mapped to colors and symbols; can be empty, seers_typenames2colorsfor detailsopts_disp(struct) – controls basic display; seers_disp_coordsetsfor details. Most fields are of opts_disp are passed directly tors_disp_coordsets, with unspecified fields in opts_disp filled with the defaults ofrs_disp_coordsets. The following field values are inserted into opts_disp based on the fields of opts_disp_enh and the graphical element being drawn:element: points rays rings neighbors data_show_method 'all' [1] 'list' 'list' 'list' data_label_method 'none'[1] 'last' 'none'[1] 'none'[1] connect_data_method 'list' 'list'[1] 'list' connect_data_linestyles 'none'[1] '--' or '-'[2] ':' [1] '-' [1] set_markers [3] 'none'[1] 'none'[1] set_tags 'rays' 'rings' 'nbrs' callout_amount 0.5[1] set_colors per ray[3] callout_colors per ray[1] - [1]: if a value is supplied value in aux.opts_disp, it is not overridden
- [2]: line style depends on whether the ray is negative (first option) or positive (second option)
- [3]: set markers and colors determined by
rs_typenames2colors
-
rays(struct) –a
ray structure, ordinarily created byrs_findrays. If empty or omitted the enhanced graphical elements will not be displayed.
Output arguments:
-
aux_out(struct) –auxiliary outputs and parameter values used
opts_disp(struct) – aux.opts_disp, with defaults and overrides filled inopts_disp_enh(struct) – aux.opts_disp_enh, with defaults filled inopts_t2nc(struct) – aux.opts_t2nc, with defaults filled inpoints(struct) – aux_out fromrs_disp_coordsetsfor display of points; omitted if opts_disp_enh.if_points=0rays(cell array of struct) – aux_out fromrs_disp_coordsetsfor display of each ray; rays{:,isign} corresponds to display of each ray in the negative direction (isign=1) and the positive direction, (isign=2); omitted if opts_disp_enh.if_rays=0;rings(cell array of struct) – aux_out fromrs_disp_coordsetsfor display of each ring; omitted if no rings are displayed or opts_disp_enh.if_rings=0nbrs(struct) – aux_out fromrs_disp_coordsetsfor connections between neighbors; omitted if no connections are displayed or opts_disp_enh.if_nbrs=0
Note regarding points and rays
- Rays are plotted before data points, so that data points overlay the rays and can be color-coded by set.
- Legend behavior: If opts_disp_enh.if_rays=1 and opts_disp_enh.if_points=0, legend is the ray label; otherwise legend is set label.
See also: rs_disp_coordsets, rs_typenames2colors, rs_findrays, rs_plot_style.
Source code in src/rs_disp_enh_coordsets.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
rs_disp_geofit(gf, aux)
aux_out=rs_disp_geofit(gf,aux)
displays the goodness of fit and model comparison statistics for geometric models fit by rs_geofit
This will create a wirerame plot of goodness of fit (d, see output gfs of rs_geofit for each model,
and, optionally, for selected models and comparisons across models that are nested by model type and/or dimension.
Input arguments:
-
gf(cell 2-D array) –geometrical fit data, typically gfs{k}.gf, where gfs is the output of
rs_geofit, containing the model fits for the kth record of a pair ofdataset structures; gf{d_out,d_in} contains the statistics for transforming a dataset of d_in dimensions to one with d_out dimensions -
aux(struct) –auxiliary options, may be omitted, with fields
opts_dgeo(struct) – options for display, with fieldsif_nestbymodel_show(int) – 1 to show all nested models, -1 to show only maximally nested models, 0 to omit; default is 1 if shuffles are present and 0 if notif_nestbydim_show(int) – 1 to show nesting by dimension;, 0 to omit; default is 1 if shuffles are present and 0 if notif_nestbydim_in_show(int) – 1 to show nesting by dimension for input, 0 if not; default is if_nestbydim_showif_nestbydim_out_show(int) – 1 to show nesting by dimension for output, 0 if not; defaults is if_nestbydim_showmodels_show_select(char or cell array of char) – selects the models to be shown in the plot of selected models; a model will be shown if at least one of the strings in models_show_select{:} is present in the model type; e.g., {'_offset','affine'} will select any model whose name contains _offset or affine; default is [], which displays all models. Caution: {} is empty, [] is empty, '' is empty, but {''} and {[]} are not.if_nestbydim_showd(int) – 1 to show d-values for models nested by dimension, 0 to omit; default is 1if_nestbydim_showd_in(int) – 1 to show d-values for models nested by input dimension, 0 to omit; default is if_nestbydim_showdif_nestbydim_showd_out(int) – 1 to show d-values for models nested by output dimension, 0 to omit; default is if_nestbydim_showdif_diag(int) – 0 to plot goodness of fit for all pairs of input and output dimensions, 1 to only plot diagonal values for input dimension equal to ouptut dimension; default is 1 if only on-diagonal values are present, otherwise 0sig_level(float) – significance level for significance flags; default is 0.05if_showsig(int) – 1 to show significance flags based on original denominator, 2 for shuffled denomiator, 3 for both, 0 to omit; default is 3if_showquant(int) – 1 to show quantile of shuffles for nesting at significance level sig_level, 0 to omit; default is 0out_label(char) – label for first coordinate of gf{}, default is 'output dim'in_label(char) – label for second coordinate of gf{}, defaulti is 'input dim'dia_label(char) – label for both coordinates of gf{}, when diagonal is plotted, default is 'dim'colors_models(cell array of color specifiers) – sequence of colors to use for model wireframes, used in cyclic order; default is {'k','b','c','m','r',[1 0.5 0],[0.7 0.7 0],'g',[.5 .5 .5],[.5 0 0]}; elements can be any valid color specifiersig_symbols(cell array of char) – symbols to mark significant values, sig_symbols{1} for original denominator, sig_symbols{2} for shuffle denominator, default is {'+','x'}sig_symsize(int) – symbol size for significance markers, default is 14lw_model(int) – line width for model, default is 2lw_nest(int) – line width for nested model, default is 2lw_quant(int) – line width for quantiles of shuffles of nested models, default is 1view(int or float 1-D array) – 3-D view descriptor, 2 is 2-d view; can also be azimuth-elevation pair, standard 3-d view is [-37.5 30]; default is 3 unless if_diag=1, in which case default is [0 0], which shows the plot in a plane
Plot selection
Plot components
Labels and formatting
opts_check(struct) – options for consistency checking, with fieldif_warn(int) – 1 to show warnings when datasets are checked for consistency, 0 to suppress; default is 1
Output arguments:
-
aux_out(struct) –auxiliary outputs and parameter values used
warnings(char) – warnings generated in checking for consistency of plotting optionswarn_bad(int) – count of warnings that prevent further processingopts_check(struct) – aux.opts_check, with defaults filled inopts_dgeo(struct) – aux.opts_dgeo with defaults filled in, and also fieldsfig_handles(cell array) – handles to the figures createdfig_names(cell array) – names of the figures created; no special chars, suitable for use in a file namemodels_shown(cell array of char) – names of models shown
See also: rs_geofit, PSG_GEOMODELS_FIT, PSG_GEOMODELS_PLOT.
Source code in src/rs_disp_geofit.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
rs_extract_coordsets(data_in, extract_list, aux)
[data_out,aux_out]=rs_extract_coordsets(data_in,extract_list,aux)
extracts or permutes the records in a dataset structure
Input arguments:
-
data_in(struct) –dataset structurecontaining n records, with fieldsds(cell array) –coordinate structure, ds{k}{idim} is an array of [nstims idim] of coordinates for the kth recordsas(cell array) –stimulus metadata structure, sas{k} is the stimulus metadata for the kth recordsets(cell array) –set metadata structure, sets{k} is the response metadata for the kth record
-
extract_list(int 1-D array) –a subset of [1:n] to extract, the records to extract
-
aux(struct) –
Output arguments:
-
data_out(struct) –extracted
dataset structurewith length(extract_list) records, same format as asdata_in1 -
aux_out(struct) –
Notes
- aux may be omitted; defaults are filled in.
- data_out.sets{k}.pipeline is copied from data_in and is not updated.
See also
Source code in src/rs_extract_coordsets.m
rs_findrays(sa, label, opts_rays)
[rays,wmsg,opts_rays_used]=rs_findrays(sa,label,opts_rays) creates a ray structure
from a single record of a stimulus metadata structure. The ray structure lists the stimuli that lie on rays (points on approximate straight lines),
rings (points in a plane at approximately equal distance from the origin), and nearest neighbors, and is used by rs_disp_enh_coordsets.
Input arguments:
-
sa(struct) –one record of a
stimulus metadata structure, e.g., data.sas{k}, where data is adataset structure -
label(char) –a paradigm name, allows for non-standard parameters for identifying rays and rings; typically omitted, defaults to []; see note below regarding nondefault parameters
-
opts_rays(struct) –options for determining criteria for rays and rings, typically omitted, with fields
coord_names(cell array of char) – fields of 'sa' to be searched for coordinates in order of priority; default is {'type_coords','btc_specoords','btc_augcoords'}ray_permute_raynums(int 1-D array) – permutation to reorder the numbering of rays; default is [] (no permutation)ray_tol(float) – tolerance for collinearity of rays; default is 10-5ray_minpts(int) – minimum number of points (other than the origin) to constitute a ray; default is 3ray_dirkeep(char) – which rays to keep, default is 'all', alternatives are 'card' (keep only cardinal directions), 'diag' (keep only diagonal directions), 'card_diag' (keep ony cardinal and diagonal directions)ray_reorder_ring(int) – 1 to standardize the order of the rings, 0 to omit; default is 1ray_plane_jit(float) – small nonzero value to standardize flattening of rays into a plane, 0 to omit; default is 10-3ray_res_ring(float) – tolerance for equal radii for a ring; default is 10-2ray_min_ring(int) – minimum number of points in a ring; default is 4ray_mindist_tol(float) – tolerance for ties for nearest-neighbor distance; default is 10-2
Output arguments:
-
rays(struct) –ray structure, with fieldsnrays(int) – number of rayswhichray(int 1-D array) – whichray(istim), in [0 nrays], is the index number of the ray that contains stimulus istim, 0 if not on a raymult(float 1-D array) – mult(istim), in [0 1], is the fractional distance of stimulus istim along its ray, 0 if not on a rayendpt(float 2-D array) – endpt(iray,:), with iray in [1 nrays], are the coordinatates of the stimulus at the end of the corresponding raynrings(int) – number of ringsrings(cell array of struct) – cell array of length nrings; rings{iring}.mult_val is the distance of the ring from the origin, and rings{iring}.coord_ptrs is int 1-d array of indices of stimuli in the ringnpairs(int) – number of nearest-neighbor pairspairs(int 2-d array) – pairs(ipair,:), with ipair in [1 npairs], are indices of stimuli in a nearest-neighbor pair
-
wmsg(char) –warning message, if any
-
opts_rays_used(struct) –opts_rays, with defaults and overrides filled in
Note regarding nondefault ray parameters
-
For specific paradigm names (passed via 'label'), selected default parameters in opts_rays are overriden as follows.
- 'bcpm24': ray_dirkeep='card_diag' and ray_minpts=2
- 'bcpp55','bcmp55','bcpm55', and 'bcmm55': ray_dirkeep='card'
-
Additional overrides can be added by editing 'psg_findray_setopts'
See also: rs_disp_enh_coordsets, PSG_DEFOPTS, PSG_FINDRAYS, PSG_TYPE_COORDS_DEF, PSG_TYPE_COORD_UTIL.
Source code in src/rs_findrays.m
rs_geofit(data_in, data_out, aux)
[gfs,xs,aux_out]=rs_geofit(data_in,data_out,aux)
fits geometrical models to the relationship between coordinates in two
dataset structures and provides transformation structures that contain these models
Input arguments:
-
data_in(struct) –dataset structurethat is the starting point of the transformations, with fieldsds(cell array) –coordinate structure, ds{k}{idim} is an array of [nstims idim] of coordinates for the kth recordsas(cell array) –stimulus metadata structure, sas{k} is the stimulus metadata for the kth recordsets(cell array) –set metadata structure, sets{k} is the response metadata for the kth record
-
data_out(struct) –dataset structurethat is the target of the transformations, same format as asdata_in; number of stimuli must be the same as data_in; stimulus names in data_in.sas{k}.typenames and data_out.sas{k}.typenames need not match but a warning is issued if they do not -
aux(struct) –auxiliary options, may be omitted, with fields
opts_geof(struct) – specification of transformations to find, with fieldsmodel_list(char or cell array of char) – model types to be fitted; default is values given inmodel_list_default; if [], then requested interactively; see notes below regarding geometric models and model definition structuremodel_list_default(char or cell array of char) – model types to be fitted when 'model_list' is not specified; default is {'procrustes_scale_offset','affine_offset','projective'}; see note below regarding customizationif_center(int) – 1 to center the data, i.e., subtract the mean across stimuli fromdata_inanddata_outbefore fitting models, 0 to omit; default is 1; note that if if_center=1, the transformations returned ingfsandxsapply to the centered data.dim_max_in(int) – maximum dimension of input dataset to use, defaults to 10dim_max_out(int) – maximum dimension of output dataset to use, defaults todim_max_indimpairs_method(char) – specifies pairing of dimensions betweendata_inanddata_out, default is 'equal'- 'equal': input dimension = output dimension
- 'all': all pairings of dimensions available in
data_inup todim_max_in, with all and dimensions available idata_out, up todim_max_out - 'din_lteq_dout': as in 'all', but input dimension must be less than or equal to output dimension
- 'din_gteq_dout': as in 'all', but input dimension must be greater than or equal to output dimension
- 'list': the pairings specified by aux.opts_geof.dimpairs_list
dimpairs_list(int 2-D array) – two-column array of pairs of dimensions for input and output, default is repmat([1:dim_max_in]',[1 2])if_stats(int) – 1 to enable statistics, 0 to omit; default is 1; a value of 0 will override a nonzeroif_nestbymodelandif_nestbydimnshuffs(int) – number of shuffles forif_nestbymodelandif_nestbydim; default is 100 if if_stats=1, 0 if if_stats=0if_frozen(int) – random number control for shuffles and initialization; 1 for same numbers every run, 0 for different random numbers each run, negative integer for a fixed seed each run; default is 1if_nestbymodel(int) – 1 to do statistics on nesting by model, 0 to omit, -1 to only do statistics for maximally nested models; default is 1; see note below regarding nestingif_nestbydim(int) – +/-1 to do statistics for nesting by dimension, 0 to omit; default is 0; see note below regarding nestingif_nestbydim_in(int) – +/-1 to do statistics for nesting by dimension of input, 0 to omit; default is if_nestbydim; see note below regarding nestingif_nestbydim_out(int) – +/-1 to do statistics for nesting by dimension of output, 0 to omit; default is if_nestbydim; see note below regarding nestingif_keep_transforms(int) – 1 to keep transforms from shuffles, 0 to omit; default is 0if_keep_transforms_nestbymodel(int) – 1 to keep transforms from nesting by model, 0 to omit; default is 0 if if_nestbymodel=0, 1 otherwiseif_keep_transforms_nestbydim_in(int) – 1 to keep transforms from nesting by dimension of input, 0 to omit; default is 0 if if_nestbydim_in=0, 1 otherwiseif_keep_transforms_nestbydim_out(int) – 1 to keep transforms from nesting by dimension of output, 0 to omit; default is 0 if if_nestbydim_out=0, 1 otherwiseif_log(int) – 1 to log overall progress, 0 to omit; default is 1if_fit_summary(int) – 1 to log a summary of fits, 0 to omit; default is 1if_fit_log(int) – 1 for a detailed log of fitting, 0 to omit; default is 0if_warn(int) – 1 to show warnings, 0 to omit; default is 1persp_method(char) – method for finding projective transformations, options are 'fmin','oneshot', or 'best'; default is 'best'- 'fmin': uses an iterative method to search for the denominator; for each trial denominator, numerator parameters are determined by standard least-squares
- 'oneshot': uses method 2 of Zhengyou Zhang, Microsoft Research Technical Report MSR-TR-2010-63 (1993, revised 2010); well-suited if the projective transformation is a close fit
- 'best' uses both methods and chooses the best-fit
Model selection
Dimension selection
Statistics
Logging and optimization
opts_check(struct) – options for consistency checking, with fieldif_warn(int) – 1 to show warnings when datasets are checked for consistency, 0 to suppress; default is 1
Output arguments:
-
gfs(cell array of struct) –gfs{k}.gf{dim_out,dim_in} contains results for the transformations from record k of
data_into record k ofdata_out, for the coordinates data_in.ds{k}{dim_in} to data_out.ds{k}{dim_out}. If there is no fitting requested for this dimension pair (see 'dimpairs_method' above), then gfs{k}.gf{dim_out,dim_in} will be empty. It contains the following fields (note that fields with 'shuff' will be absent if if_nestbymodel=0, and fields with 'shuff_nestdim_in' and 'shuff_nestdim_out' will be absent if if_nestbydim_in or if_nestbydim_out are absent)model_types_def(struct) – model_types_def.model_types is a cell array of the models fitted; model_types_def.(model).nested is a cell array of the names of the nested models testedref_dim(int) – dimension of the input dataset (same as dim_out)adj_dim(int) – dimension of output dataset (same as dim_in)opts_geofit(struct) – options used for fittingd(float 1-D array) – d(m) is the normlizded error for model m, equal to the sum of the squares of the deviations of data_out.ds{k}{dim_out} from the modeled values, normalized by the sum of their distances from their centroid. Here and below, the index m denotes fits for the model type listed in model_types_def.model_types{m};- transforms (1-D cell array}: transforms{m} are the parameters for the transformation; see
transformation structurefor details on how these are parameterized d_shuff(float 4-D array) – d_shuff(m,shuff,nest,normtype) is the normalized error for each shuffle of the nested model; normtype=1 normalizes by the centroid of the shuffled data, normtype=2 normalizes by the centroid of the original datasurrogate_count(int 3-D array) – surrogate_count(m,nest,normtype) counts the number of shuffles for which d_shuff(m,shuff,nest,normtype) is less than d(m)nestdim_in_list(int) – list of the lower dimensions used for nesting by input dimensiond_shuff_nestdim_in(float 4-D array) – d_shuff_nestbydim_in(m,shuff,nest,normtype) is the normalized error for each shuffle for a model with fewer input dimensions; normtype=1 normalizes by the centroid of the shuffled data, normtype=2 normalizes by the centroid of the original datasurrogate_count_nestdim_in(int 3-D array) – surrogate_count_nestdim_in(m,nest,normtype) counts the number of shuffles for which d_shuff_nestdim_in(m,shuff,nest,normtype) is less than d(m)nestdim_out_list(int) – list of the lower dimensions used for nesting by output dimensiond_shuff_nestdim_out(float 4-D array) – d_shuff_nestbydim_out(m,shuff,nest,normtype) is the normalized error for each shuffle for a model with fewer output dimensions; normtype=1 normalizes by the centroid of the shuffled data, normtype=2 normalizes by the centroid of the original datasurrogate_count_nestdim_out(int 3-D array) – surrogate_count_nestdim_out(m,nest,normtype) counts the number of shuffles for which d_shuff_nestdim_out(m,shuff,nest,normtype) is less than d(m)
-
xs(struct) –the transformations fit for dim_out=dim_in, as
transformation structurescompatible withrs_xform_apply. There is a field xs.(model_name) for each model_name specified in model_list. xs.(model_name), has fieldsclass(char) – the transformation class ('mean','procrustes','affine', 'projective','pwaffine')xforms(struct) – xs.(model_name).xforms.ts{k}{dim_in}: the transformation to be applied to coordinates in data_in.ds{k}{dim_in} to fit coordinates in data_out.ds{k}{dim_in}. Seetransformation structurefor further details. If no fitting is requested for this dimension pair, then it will be empty.
-
aux_out(struct) –auxiliary outputs and parameter values used, with fields
Note regarding geometric models
-
Model types to be fit are specified by the entries in opts_geof.model_list. The following model types are available:
- 'mean': all input values mapped to a single output value
- 'procrustes_noscale_nooffset': rotation (and possibly reflection), no rescaling, no translation
- 'procrustes_scale_nooffset': rotation (and possibly reflection), rescaling allowed, no translation
- 'procrustes_noscale_offset': rotation (and possibly reflection), no rescaling, translation allowed
- 'procrustes_scale_offset': rotation (and possibly reflection), rescaling allowed, translation allowed
- 'affine_nooffset' : linear transformation, no translation
- 'affine_offset': linear transformation, translation allowed
- 'projective': projective transformation
- 'pwaffine': piecewise affine with one cutplane; two linear transformations with agreement on the cut
- 'pwaffine_2': piecewise affine with two cutplanes; four linear transformations, with agreement on the cuts
-
The list of available model types can be obtained by getfield(psg_geomodels_define,'model_types')
- To determine the model class (see
transformation structures) for model type mt: m=psg_models_define; getfield(m.(mt),'class') - To determine the models nested in model type mt:
m=psg_models_define; getfield(m.(mt),'nested') - See
transformation structuresfor further details on how the models are parameterized and nesting
Note regarding customization
The default model list can be changed by editing the line containing generic.opts_geof.model_list_default in rs_aux_defaults_define, running it
once, and saving the workspace as rs_aux_defaults.mat.
Note regarding model definition structure
- mdef=rs_geofit() returns a model definition structure, which defines the available models and their characteristics.
- mdef.model_types is a cell array {model_name1,model_name2,...} of the names of available models
- mdef.(model_name) defines each model
- mdef.(model_name).class is the model class: 'mean','procrusetes,'affine','projective','pwaffine' (see
rs_xform_apply??how to hyperlink) - mdef.(model_name).nested lists the names of the nested models
Note regarding nesting and model selection
-
Nesting by model type: Some models are extensions of others. For example, the affine_offset model extends the affine_noofset model, by allowing offsets. The more general model will always provide a fit that is at least as good as the less-general model, but will have more parameters. The if_nestbymodel option provides a way to determine whether the improvement in fit is better than would be expected by chance.
- To do this, rs_geofit (i) fits with the less-general model, then (ii) shuffles the residuals (the difference between the predicted coordinates in ds_out and the actual coordinates) among the stimuli, and (iii) refits with the more general model. If the more general model provides a fit to the original data that is better than chance, this should rarely result in an improved fit.
- Goodness of fit values and tallies are provided in gfs{k}{dim_out,dim_in}.d_shuff and gfs{k}{dim_out,dim_in}.surrogate_count
-
Fine-tuning: if_nestbymodel=+1 vs -1
- With if_nestbymodel=+1, all nested models specified by model_list are examined
- with if_nestbymodel=-1, only the maximally nested models are examined. (Model B is considered to be maximally nested in model A if there is no intermediate nested model, i.e., no model X for which B is nested in X, and X is nested in A.)
-
Nesting by dimension: Models with more coordinates have a greater number of parameters than models with fewer coordinates, and thus may also be viewed as extensions. The if_nestbydim_in and if_nestbydim_out options provide a way to determine whether an improvement due to adding dimensions is better than would be expected by chance.
- To do this, rs_geofit (i) fits a model with fewer coordinates, then (ii) shuffles the added coordinates among the stimuli, and (iii) refits with the more general model. If the more general model provides a fit to the original data that is better than chance, this should rarely result in an improved fit.
- Goodness of fit values and tallies are provided in gfs{k}{dim_out,dim_in}.d_shuff_nestdim_[in|out] and gfs{k}{dim_out,dim_in}.surrogate_count_nestdim_[in|out].
-
Fine-tuning: if_nestbydim_[in|out]=+1 vs -1
- With if_nestbydim_[in|out]=+1, input and output coordinates are used as is for the nesting calculations. This is appropriate if the input and output coordinates themselves are nested, i.e., if data_in.ds{k}{dim_in}(:,1:r)=data_in.ds{k}{r}, for dim_in>r (and similarly for dim_out)
- However, if this is not the case (for example, if each each set of coordinates data_in.ds{k}{dim_in} is arbitrarily rotated), this analysis could be misleading, since a coordinate in a low-dimensional coordinate set data_in.ds{k}{r} could be rotated into a higher coordinate in data_in.ds{k}(idim}, for idim>r.
- To avoid this possible pitfall, use if_nestbydim_[in|out]=-1. This applies principal components analysis to the coordinates prior to the analysis of nesting.
See also: rs_aux_customize, rs_check_coordsets, PSG_GEOMODELS_FIT, PSG_GEOMODELS_PLOT, PSG_GEOMODELS_DEFINE, PSG_GEOMODELS_NESTORDER, rs_disp_geofit.
Source code in src/rs_geofit.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |
rs_get_coordsets(fullnames, aux)
[data_out,aux_out]=rs_get_coordsets(fullnames,aux): reads one or more coordinate files into a dataset structure
This is the preferred method for bringing coordinates from one or more files into a dataset structure suitable for display and geometrical analysis.
- For files generated by analysis of similarity judgments via [??how to refer to Python package], this will also import the goodness-of-fit data.
- A
ray structurewill be created. - If only a single data file is to be read,
rs_read_coorddatacan also be used. - This can also create a
coordinate structurebased on aquadratic form model, and can augmentbinary texture domaindata by symmetry. -
To import coordinates generated externally or that exist as arrays rather than in a file, use
rs_import_coordsets. -
For non-interactive reading, provide aux.nsets, aux.opts_read.data_fullnames, aux.opts_read.input_type, and set aux.opts_read.if_auto=1.
Input arguments:
-
fullnames(char or cell array of char) –full file name with path; if empty, it will be requested interactively. File names must contain the string '_coords'. See note below regarding setup files.
-
aux(struct) –a structure, can be omitted, with fields
nsets(int) – number of records to read, if zero (default), then requested at console, with console option to switch to guiopts_read(struct) – can be omitted, with fields listed belowif_gui(int) – 1 to use graphical interface to get files if file names are not supplied (default), 0 to use console; ignored if nsets=0; see note below regarding customizationif_log(int) – 1 to log progress, 0 to omit; default is 1; see note below regarding customizationif_auto(int) – 1 not to ask for confirmations, 0 to ask; default is 0; see note below regarding customizationnfiles_max(int) – maximum number of files to read; default is 100input_type(int or int 1-D array) – 1 for reading a coordinate file, 2 for reading aquadratic form model, 0 to ask; cycled through for each dataset; default is 0; see note below regarding customizationdata_fullname_def(char) – prompt for data file name; see note below regarding customizationui_filter(char) – file name filter that appears in graphical user interface when if_gui=1; defaults to '*_coords';see note below regarding customizationif_warn(int) – 1 to show warnings, 0 to omit; default is 1; see note below regarding customizationtype_coords(float 2-D array) – stimulus coordinates to use for non-reserved domain names, one row for each stimulus; default is emptytype_coords_def(char) – stimulus coordinates to use if type_coords is unspecified or empty; options are 'none', 'zeros', 'ones', or 'eye', seers_import_coordsets; default is 'none'; seers_import_coordsetsfor further details and how to customizedomain_list_def(cell array) – paradigm names for generic domain experiments; default is {'cars','tools','dwellings'}; determined by customization during installparadigm_type_def(char) – default paradigm type; default is determined by customization during installcoord_string(char) – a string in a data file name that delineates the end of the domain name; defaults to '_coords'setup_fullnames(cell array) – setup file full names; if empty, will be requested at console or via guisetup_fullname_def(char) – prompt for setup file namesetup_suffix(char) – suffix added to paradigm name to create the setup file name; default is 'S'type_class_aux(char) – a specified domain name and type_classif_symaug(int) – 1 to enable symmetry augmentation, 0 to omit, -1 to ask; default is 0if_symaug_log(int) – 1 to log symmetry augmentation, 0 to omit; default is 0sym_apply(char) – type of symmetry to apply; default is 'full', options are 'hflip','vflip','rot180','rot90','hvflip','diag','full','none'permutes(struct) – typically omitted; each field is a suggested ray permutation for the corresponding paradigm name, e.g., permutes.bgca=[2 1 3 4] specifies a reordering of the rays for paradigm 'bgca'permutes_ok(int) – typically omitted; 1 to accept suggested ray permutation, 0 to keep standard order; default is 1; see note below regarding customizationif_uselocal(int) – typically omitted; 0 to use options in rs_aux_defaults, 1 is reserved for maintenance; default is 0opts_qpred(struct) – a structure, can be omitted, with options forquadratic form model, with fieldsqform_datafile_def(char) – default name of the file with quadratic form models containing a structure r; see notes below quadratic form model and customizationqform_modeltype(int or int 1-D array) – list of indexes into qform_datafile_def for choice of model, used cyclically across records as needed. 0 -> ask at console; detault is 1 see note below re customizationif_log(int) – 1 to log calculation of quadratic form model, 0 to omit; default is 0if_pca_centroid(int) – 1 to force centroid of coordinates to 0 via PCA method, 0 to omit; default is 1negeig_makezero(int) – 1 to set negative eigenvalues to 0, 1 to omit; default is 1negtol(float) – eigenvalues between 0 and -negtol are set to zero before checking for negative eigenvalues; default is 10^-7opts_rays(struct) – options for identifying rays, may be omitted; seers_findraysfor detailsopts_check(struct) – options for consistency checking, with fieldif_warn(int) – 1 to show warnings when datasets are checked for consistency, 0 to suppress; default is 1
Options related to stimulus coordinates, domains, and setup files (see notes below)
Options for symmetry augmentation (
binary texture domaindata only)Options for internal use and maintenance
Output arguments:
-
data_out(struct) –dataset structure, containing one records, with fieldsds(cell array) –coordinate structure, ds{k}{idim} is an array of [nstims idim] of coordinates for the kth recordsas(cell array) –stimulus metadata structure, sas{k} is the stimulus metadata for the kth recordsets(cell array) –set metadata structure, sets{k} is the response metadata for the kth record
-
aux_out(struct) –auxiliary outputs and parameter values used, with fields
warnings(char) – warnings generated during consistency checkwarn_bad(int) – number of warnings that prevent further processingrayss(cell array of struct) – rayss{k} is theray structurefor the kth recordopts_read(cell array of struct) – opts_read{k} is aux.opts_read for reading the kth record, with defaults filled inopts_rays(cell array of struct) – opts_rays{k} are the options used for creating theray structurefor the kth recordopts_qpred(cell array of struct) – opts_qpred{k} are the options used for creating thequadratic form modelfor the kth record along withvar_tot(float) – total variance of the coordinatesvar_ex(float 1-D array) – variance explained by each dimension of the modelpredcoords(float 2-D array) – predcoords(istim,idim) is the model coordinate for stimulus istim in dimension idim
opts_check(struct) – aux.opts_check, with defaults filled insyms_list(struct) – structure with results of symmetry augmentationsym_apply(char) – the symmetry applied, see 'sym_apply' aboveprimary(int 1-D array) – primary(k) is pointer to the data that was augmented by symmetry to yield the kth recordaug(int 1-D array) – aug(k) indicates the symmetry that was used to yield the kth record, e.g., if there are n_sym total symmetries (e.g., n_sym=8 for 'full'), then aug is in [1:n_sym]. The pairs [primary(k) aug(k)] are unique; a contiguous block of n_sym pairs share one value of primary(k) and have sequential values of aug(k)syms_applied(cell array of char) – syms_applied{k} are thebinary texturecoordinates after symmetry transformation for record k
Note regarding domain names, stimulus coordinates, and setup files
-
The domain name is determined from the data file name based on the string preceding '_coords' (or, opts_read.coord_string, if customized). This in turn determines how stimulus coordinates are specified.
- For non-reserved domain names (opts_read.type_class_aux, or any domain in opts_read.domain_list_def), stimulus coordinates are specified by 'type_coords' and no setup file is used.
- Other domain names are reserved, and stimulus coordinates are specified by a 'setup file', whose suggested name is constructed from the data file name up to the string preceding opts_read.coord_string, and appending opts_read.setup_suffix
-
The domain name is also used to determine a 'type_class', which is used internally. This is carried out in psg_coorddata_parsename, as follows:
- The domains 'faces*' are reserved; type_class is faces_mpi; used with a setup file
- The domain 'irgb' is reserved; type_class is 'irgb'; used with a setup file
- The domain 'mater' is reserved; type_class is 'mater'; used with a setup file
- The domain opts_read.type_class_aux is NOT reserved; type class is type_class_aux; no setup file used
- Any domain that is listed in opts_read.domain_list_def is NOT reserved; type class is 'domain'; no setup file used
-
Otherwise, type_class is set to opts_read.type_class_def, ('btc' unless customized); used with a setup file
-
When a
dataset structureis written byrs_write_coordsets, the setup file information, if any, will be embedded. When that file is read in and an embedded setup file is detected, no setup file is requested. - Also see note below regarding customization
Note regarding quadratic form model
- Quadratic form models may be used to generate a
coordinate structurebased on stimulus coordinates. -
The file must a cell array r, and each r{imodel} has at least has structure r The quadratic form model file must contain a field r, which must contain
- results.qfit (float 2-D array): a symmetric matrix indicating the quadratic form which, when applied to stimulus coordinates, yields the model coordinates
- setup.label (char): a label for the model
-
See demos/opposites_qform_example.mat for an example file with four quadratic form models, applicable to a stimulus set in which stimuli have three coordinates
Note regarding customization
-
The defaults for the following parameters can be set by editing the line containing generic.opts_read.[param_name] in
rs_aux_defaults_define, running it once, and saving the workspace as rs_aux_defaults.mat.- if_gui
- ui_filter
- if_log
- if_warn
- if_auto
- data_fullname_def
- setup_fullname_def
- domain_list_def
- setup_suffix
- permutes_ok
- coord_string
- type_class_aux
- if_symaug
- sym_apply
- if_symaug_log
-
The defaults for the following parameters can be set by editing the line containing generic.opts_qpred.[param_name] in
rs_aux_defaults_define, running it once, and saving the workspace as rs_aux_defaults.mat.- qform_datafile_def
- qform_modeltype
See also: rs_aux_customize, rs_findrays, rs_check_coordsets, PSG_GET_COORDSETS, PSG_COORDDATA_PARSENAME.
Source code in src/rs_get_coordsets.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
rs_graphic_hints()
graphic_hints=rs_graphic_hints() provides version-specific hints for graphics capabilities, including how alpha blending should be implemented
Output arguments:
-
graphic_hints(struct) –descriptor of version-specific graphics capabilities, with fields
if_alpha_color_line(int) – 1 if line color property allows for alpha as fourth component, otherwise 0if_alpha_color_line_marker(int) – 1 if if marker edge color property on a line allows for alpha as a fourth component, otherwise 0if_alpha_scatter_marker_edge(int) – 1 if MarkerEdgeAlpha is a property of Scatter, otherwise 0if_alpha_scatter_marker_face(int) – 1 if MarkerFaceAlpha is a property of Scatter, otherwise 0
See also: rs_plot_style.
Source code in src/rs_graphic_hints.m
rs_import_coordsets(coords, aux)
[data_out,aux_out]=rs_import_coordsets(data_in,aux) imports coordinates into a dataset structure with one record
This is the preferred method for bringing coordinates (as arrays) into the rs package, to create a dataset structure with one record, suitable for display and geometrical analysis.
- If more than one record is to be combined into a single
dataset structure, thenrs_concat_coordsetscan be used to combine several one-recorddataset structurescreated here into a singledataset structure. - If the record is in a file,
rs_read_coorddatacan be used for a single record, orrs_get_coordsetsfor multiple files. - For multiple coordinate sets collected with the same experimental paradigm, use
rs_get_coordsets, or use this routine and combine multipledataset structuresinto a singledataset structurewithrs_concat_coordsets. - No
ray structurewill be created; to do so, use rs_findrays - To createa a
coordinate structurebased on aquadratic form model, users_findraysand supply 'type_coords' to indicate the stimulus coordinates
Input arguments:
-
coords(float 2-D array, or cell array of float 2-D arrays) –the coordinates; see note below regarding coordinates.
-
aux(struct) –a structure, can be omitted, with fields
opts_import(struct) – metadata, can be omitted, with fields listed below. Fields nstims, typenames, and type_coords are used to create thestimulus metadata structure; fields type, paradigm_type, paradigm_name,extra, subj_id, subj_id_short, label, and label_long are used to create theset metadata structure. Any or all can be omitted.nstims(int) – number of stimuli; default determined from first non-empty entry in coordstypenames(cell array) – unique labels for stimuli; length should be equal to nstims; default is opts_import.typename_prefix followed by a sequential number, formatted with opts_import.typename_ndigitstypename_prefix(char) – prefix auto-generated stimulus names; default is 'type_'; see note below regarding customizationtypename_ndigits(int) – number of digits in suffix for auto-generated stimulus names; default is 2; see note below regarding customizationtype_coords(float 2-d array) – array with nstims rows specifing thestimulus coordinates; default is determined by opts_import.type_coords_deftype_coords_def(char) – method for auto-generation ofstimulus coordinates; default is 'none'; see note below regarding customization- 'none': type_coords=[]
- 'zeros': type_coords=zeros(nstims,1)
- 'ones': type_coords=ones(nstims,1)
- 'eye': type_coords=eye(nstims)
type(char) – overall category of coordinates; default is 'data'; alternatively, 'model' for coordinates originating in a computational modelparadigm_type(char) – overall category of experiment; default is 'unknown'; see note below regarding customizationparadigm_name(char) – subcategory of paradigm_type; default is opts_import.paradigm_type; see note below regarding customizationsubj_id(char) – full subject identifier; default is 'unknown'; see note below regarding customizationsubj_id_short(char) – short form of subj_id, e.g., for plot labels; default is opts_import.subj_idextra(char) – free-form identifier; default is []; see note below regarding customizationlabel_long(char) – data source, typically a file path and name; default is 'unknown'; see note below regarding customizationlabel(char) – short form of label_long; default is opts_import.label_long; see note below regarding customization
-
opts_check: options for consistency checking, with field
if_warn(int) – 1 to show warnings when datasets are checked for consistency, 0 to suppress; default is 1
Output arguments:
-
data_out(struct) –dataset structurewith one record, and fieldsds(singleton cell array) –coordinate structure, ds{1}{idim} is an array of [nstims idim] of coordinatessas(singleton cell array) –stimulus metadata structure, sas{1} is the stimulus metadata for the recordsets(singleton cell array) –set metadata structure, sets{1} is the response metadata for the record
-
aux_out(struct) –auxiliary outputs and parameter values used, with fields
Note regarding coordinates
- if 'coords' is a 2-dimensional array of size [nstims dmax], then coords(:,1:idim) is taken to be the coordinate set data_out.ds{1}{:,idim}, for each idim=1,...,dmax
- if 'coords' is a cell array, then coords{idim} should be of size [nstims idim] or empty, and, if non-empty, is taken to be the coordinate set for dimension idim.
Note regarding customization
The default values of these parameters can be changed by editing rs_aux_defaults_define, running it
once, and saving the workspace as rs_aux_defaults.mat.
For example, to change the default paradigm
type to 'cars', add or edit the line generic.opts_import.paradigm_type='cars'
in the section in which generic.opts_import fields are defined.
- typename_prefix
- typename_ndigits
- type_coords_def
- paradigm_type
- paradigm_name
- subj_id
- subj_id_short
- extra
- label_long
- label
See also: rs_concat_coordsets, rs_aux_customize, rs_check_coordsets, PSG_TYPE_COORDS_DEF.
Source code in src/rs_import_coordsets.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
rs_knit_coordsets(data_in, aux)
[data_out,aux_out]=rs_knit_coordsets(data_in,aux)
knits a dataset structure into a consensus, and provides and displays statistics
Each of the records in the dataset structure data_in should contain the same stimuli,
and in the same order, as determined by the strings in data_in.sas{k}.typenames for the record k.
Missing data (e.g., for the stimulus s labeled by data_in.sas{k}.typenames{s}) should be indicated by
NaN's in the row data_in.sets{k}{idim}(s,:), a row of length idim. The dataset structure returned by rs_align_coordsets
meets these requirements.
Input arguments:
-
data_in(struct) –dataset structureto be processed, with fieldsds(cell array) –coordinate structure, ds{k}{idim} is an array of [nstims idim] of coordinates for the kth recordsas(cell array) –stimulus metadata structure, sas{k} is the stimulus metadata for the kth recordsets(cell array) –set metadata structure, sets{k} is the response metadata for the kth record
-
aux(struct) –auxiliary inputs, may be omitted, with fields
opts_knit(struct) – options for knitting and consistency checking, with fields to controlallow_offset(int) – 1 to allow translational offset, 0 does not allow; default is 1allow_scale(int) – 1 to allow scaling of each dataset into the consensus, 0 does not allow; default is 0allow_reflection(int) – 1 to allow reflection, 0 does not allow; default is 1if_normscale(int) – 1 to normalize consensus to size ofdata_in(determined by geometric mean of scale factors for each dataset), 0 does not (no effect if allow_scale=0); default is allow_scaleif_pca(int) – 1 to rotate the consensus coordinates in data_out into its principal components, 0 does not; default is 0if_stats(int) – 1 to do statistics of variance explained, 0 does not; default is 0nshuffs(int) – number of shuffles for calculating statistics; default is 500 if if_stats=1, 0 if if_stats=0; see note below regarding statistics and plotsif_frozen(int) – random number control for shuffles and initialization; 1 for same numbers every run, 0 for different random numbers each run, negative integer for a fixed seed each run; default is 1; see notes below regarding statistics and Procrustes consensus algorithmdim_max_in(int) – maximum dimension of data_in.ds to use; default is maximum available across all datasetsdim_list_in(int 1-D array) – list of dimensions to use from data_in.ds, must be unique; default is [1:dim_max_in]dim_aug(int) – number of dimensions to add for knitted datasets in data_out.ds; default is 0; see note below regarding Procrustes consensus algorithmdim_list_out(int 1-D array) – list of dimensions to create in data_out.ds, must be same length as dim_list_in, no less than corresponding elements of dim_list_in, and unique; default is [1:dim_list_in]+dim_augif_dim_heuristics(int) – 1 to always show heuristics as to whether there are sufficient constraints for the requested dimensions, 0 only if insufficient constraints; default is 0if_plot(int) – 1 to plot statistics, 0 does not; default is if_statsshuff_quantiles(float 1-D array) – quantiles to plot; default is [0.01 0.05 0.5 0.95 0.99]if_remove_path_label(int) – 1 to remove path from filename when used as a label (in data_in.sets{:}.label), 0 does not; default is 1knit_stats(struct) – include to replot a previous analysis, otherwise omit; see note below regarding replottingknit_stats_setup(struct) – include to replot a previous analysis, otherwise omit; see note below regarding replottingif_log(int) – 1 to log progress, 0 to suppress; default is 1pcon_init_method(int or char) – typically omitted; default is 0, leading to 'pca' method for initializingprocrustes_consensus; see note below regarding Procrustes consensus algorithm for other optionsif_swarm(int) – 1 to enable swarm optimization (overriding pcon_init_method), 0 to disable; default is 0; see note below regarding swarm optimizationif_initpca_rot(int) – typically omitted, default is 1 unless any of dim_list_out>dim_list_in; see note below regarding Procrustes consensus algorithmmax_iters(int) – maximum number of iterations for Procrustes consensus; default is 1000; see note below regarding Procrustes consensus algorithmmax_rmstol(float) – maximum change ofcoordinates for consensus solution; default is 10^-5; see note below regarding Procrustes consensus algorithmkeep_details(int) – 1 to return details of Procrustes consensus minimization, 0 does not; default is 0; see note below regarding Procrustes consensus algorithmpcon_initial_guess(cell array) – specified initial guess for Proccrustes minimization, typically omitted; see note below regarding Procrustes consensus algorithmpcon_alignment(cell array) – specified alignment for Procrustes minimization, typically omitted; see note below regarding Procrustes consensus algorithmswarm(struct) – if present, sets options for swarm optimization (see note below regarding swarm optimization); fields areif_log(int) – 1 for logging swarm optimization, 0 to suppress; default is 0if_frozen(int) – 1 for same numbers each run, 0 for different random numbers each run, negative integer for a fixed seed each run; default is 1max_niters(int) – maximum number of iterations to determine best initialization for swarm; default is 50max_rmstol(float) – tolerance for stopping iterations to dtermine best initializatio for swarm; default is 10^-4nrand(int) – number of initial guesses based on random numbers; default is 10
Transformations
Statistics and shuffles
Dimension selection
Plotting and replotting
Logging and optimization
opts_check(struct) – options for consistency checking, with fieldif_warn(int) – 1 to show warnings when datasets are checked for consistency or sufficient overlaps, 0 to suppress; default is 1
opts_pca(struct) – options for principal components analysis of consensus, typically omitted, only relevant if if_pca=1opts_align(struct) – options for alignment of data, typically omitted; see note below regarding recalculation of alignmentopts_rays(struct) – options for rays, typically omitted; see note below regarding rayssa_pooled(struct) – include to avoid recalculation of alignment, otherwise omit; see note below regarding recalculation of alignmentdata_align(struct) – include to avoid recalculation of alignment, otherwise omit; see note below regarding recalculation of alignment
Output arguments:
-
data_out(struct) –dataset structurewith a single record consisting of the consensus coordinates fromdata_in, same format as asdata_in -
aux_out(struct) –auxiliary outputs and parameter values used
warnings(char) – warnings generated during consistency checkwarn_bad(int) – number of warnings that prevent further processingopts_knit(struct) – aux.opts_knit, with defaults filled inopts_check(struct) – aux.opts_check, with defaults filled inopts_pcon(cell array of struct) – opts_pcon{idim} are the options used in Procrustes alignment for model dimension idimopts_pca(struct) – aux.opts_pca, with defaults filled inopts_align(struct) – aux.opts_align, with defaults filled inopts_rays(cell array with one element) – opts_rays{1} is a structure which contains the options used for creating rays in data_outrayss(cell array with one element) – rayss{1} is theray structurefor data_out; see note below regarding rayscoords_havedata(int 2-D array) – coords_havedata(s,k)=1 if the stimulus data_out.sets{:}.typenames{s} is present and not NaN in record k ofdata_in, 0 otherwisecomponents(struct) – adataset structure, the kth record corresponds to the kth record ofdata_inafter transformation to the consensus; all stimuli in data_out will be included but coordinates for stimuli not in data_in.sas{k} will be NaNknit_stats(struct) – statistics of knitting; see notes below regarding statistics and replotting a previous analysisknit_stats_setup(struct) – parameters extracted from aux.opts_knit, along with the additional fields below; see note below regarding replotting a previous analysisnsets(int) – number of records indata_innstims(int) – number of stimulidataset_labels(cell array of char) – dataset labels, from data_in.sets{:}.labelstimulus_labels(cell array of char) – stimulus labels, from data_out.sas{1}.typenames
fig_handle(handle) – handle to figure created (present only if statistics are plotted)ts_pca(cell array) – ts_pca{idim}{k} is the transformation from data_in.ds{k}{idim} to the consensus, taking into account final pca; present only if aux.opts_knit.if_pca=1 The transformation is ts_pca{idim,k}.scaling*[data_in{k}{idim}]*ts_pca{idim}{k}.orthog+ts_pca{idim}{k}.translation. Note that translation may be nonzero even if allow_offset=0, since this is the best transformation from the original data to the consensus -- which may include a translation even if the consensus is calculated wthout allowing translation. If no translation is desired, then set this field to zeros(1,idim). If dim_list_out>dim_list_in, then data_in{k}{idim} needs to be right-padded by columns of zeros for missing dimensions.details(cell array of struct) – details{idim} contains details of the convergence towards knitting for data_in.ds{:}{idim}; present only if aux.opts_knit.keep_details=1; fields includets_cum(cell array) – ts_cum{m}{k} is the transformation found from record k, i.e., from data_in.ds{k}(istim,:), to the current consensus, on iteration mrms_change(float 1-D array) – rms_change(m) is the rms change of the consensus coordinates from the previous iterationconsensus(float 3-D array) – consensus(istim,:,m) are theconsensus coordinates on iteration mz(float 4-D array) – consensus(istim,:,k,m) are the coordinates data_in.ds{k}(istim,:) transformed to match the consensus on dimension mrms_dev(float 2-D array) – rms_dev(k,m) is the rms deviation of record k from the consensus, after the current transformationinitial_guess(float 2-D array) – initial_guess(istim,idim) are the coordinates of stimulus istim used for the initial guess for the consensusalignment(float 2-D array) – alignment(istim,idim) are the coordinates of stimulus istim used to align the consensusinitialize_use(int 1-D array) – initialize_use(istim,1) is the reocrd is used to initialize each point (if initialize_set>0)swarm(struct) – details from swarm optimization, present only if opts_knit.if_swarm=1 (see note regarding swarm optimization), with fieldsrms_dev_total_min(float) – root-mean-squared deviation for best alignment from preliminary swarm runsrms_dev_total_definitive(float) – root-mean-squared deviation for best alignment for definitive runclass_name_min(char) – the class that produced the best alignment in preliminary runsitry_min(int) – the instance in the class that produced the best alignment in preliminary runsopts_definitive(struct) – the options in opts_knit that produced the best alignment in preliminary runsif_def_eq_swarm(int) – 1 if halting parameters (max_niters, max_rmstol) for preliminary and definitive runs matchinit_components(struct) – results of swarm optimizations based on component datasetsinit_pca(struct) – results of swarm optimizations based on principal componentsinit_random(struct) – results of swarm optimizations based on random starts
Note regarding propagation of fields from data_in to data_out
- For all records with data_in.sets{k}.type='data', the strings in data_in.sets{k}.paradigm_type must agree.
- The 'type' field of data_in.sets{1} is propagated to data_out.sets{1}
- If present, the 'paradigm_type' field common to data_in.sets{:} for all k for which data_in.sets{k}.type='data' is propagated to data_out.sets{1}
-
The following fields of data_in.sets{:} are concatenated with + signs in between and propagated to data_out.sets{1}
- paradigm_name
- subj_id
- subj_id_short
- label_long
- label
- extra
-
pipeline field of data_out.sets{1}:
- data_out.sets{1}.pipeline.type='knit'.
- data_out.sets{1}.pipeline.sets_combined{:} contains metadata from all records of
data_in
Note regarding statistics and plots
-
If aux.opts_knit.if_stats=1, variance explained by the consensus coordinates are calculated and returned in aux_out.knit_stats, in the following fields (rmsd=root-mean-squared deviation):
- rmsdev_overall (float 1-D array): rmsdev_overall(idim) is the rmsd across all records and stimuli
- rmsdev_setwise (float 2-D array): rmsdev_setwise(idim,k): rmsd within record k, across stimuli
- rmsdev_stmwise (float 2-D array): rmsdev_stmwise(idim,istim): rmsd within stimulus istim, across records
-
The counts for each of these calculations are counts_[overall|setwise|stmwise], and the available rmsd (from zero) is given by rmsavail_[overall|setwise|stimwise].
- If aux.opts_knit.nshuffs>0 (default is 500), then a parallel computation is done after random shuffles of the stimulus labels within each record, and the results are returned in rmsdev_[overall|setwise|stimwise]_shuff.
- For the shuffled quantities, the first two dimensions are the same as the unshuffled quantities; dimension 3 is always 1; dimension 4 (length: nshuffs) is which shuffle; dimension 5 (length: 2) is the mode: 1 for last coordinate only shuffled, 2 for all coordinates shuffled. To control whether the same random number seed is used on each run, use aux.opts_knit.if_frozen (default is 1).
-
if aux.opts_knit.if_plot=1 (default if if_stats=1), then a figure is created, with four panels:
- a heatmap of rmsdev_setwise as a function of dimension
- a heatmap of rmsdev_stmwise as a function of dimension
- a comparison of the unexplained portion of rmsdev_overall (black) to quantiles of rmsdev_overall_shuff (mode 1: magenta, mode 2: red). Quantiles are specified by shuff_quantiles; if nshuffs=0, shuffled values will not be plotted
- a comparison of the explained rmsd, parallel to the above, with available rmsd in blue
-
Other fields in aux_out.knit_stats are the following. Note that ds_components and ts are analogus to the fields components and ts_pca] in aux_out, except that ds_components and ts do not include the rotation to principal components (if requested by aux.opt_knit.if_pca=1). This is not needed for the variance statistics. For a transformation that includes the rotation, see aux_out.ts_pca.
- opts_pcon (struct): supplied options for Procrustes consensus algorithm
- opts_pcon_eachdim (cell array of struct): opts_pcon_eachdim{idim} are the options used for dimension idim
- ds_knitted (cell array): ds_knitted{idim} are the consensus coordinates
- ds_components (cell array): ds_components{k}{idim} are the coordinates for record k that most closely match the consensus
- ts (cell array): ts{idim}{k} is the Procrustes transformation for record k. The transformation is
[ds_components{k}{idim}]=ts{idim}{k}.scaling*[data_in.ds{k}{idim}]*ts{idim}{k}.orthog+ts{idim}{k}.translation; see
transformation structuresfor further details. If dim_list_out>dim_list_in, then data_in.ds{k}{idim}] needs to be right-padded by columns of zeros for missing dimensions.
Note regarding recalculation of alignment
The first step in forming a consensus is alignment, which identifies the common stimuli among the records of data_in, and to
place them in the same order. By default, this is carried out in rs_knit_coordsets by a call to rs_align_coordsets, using options aux.align_opts.
This recalculation can be avoided by supplying aux_out from a
previous call to rs_align_coordsets, as follows: aux.sa_pooled=aux_out.sa_pooled, aux.data_align=aux_out.data_out
Note regarding Procrustes consensus algorithm
- To find a consensus set of coordinates, the coordinates in each record of
data_inare rotated, and optionally translated (if allow_offset=1), scaled (if allow_scale=1), and reflected (if allow_reflection=1). These transformations are carried out for separately for each set dimension for which coordinates are present in all of the records, i.e., for which data_in.ds{k}{idim} exists for all k. - The algorithm, in procrustes_consensus.m, is iterative. Briefly, after an initial guess is determined, a Procrustes transformation is found that minimizes the rms deviation between each record and the current guess. The guess is then revised by setting each stimulus' coordinates equal to the centroid of the coordinates of that stimulus across the records. To avoid drift of the updated guess, it is Procrustes-transformed for closest match to an alignment coordinate set (the alignment set, unless otherwise specified, is equal to the initial guess).
- The iteration ends when either the number of iterations exceeds max_niters (default=1000), or the rms change of the guess is less than max_rmstol (default=10^-5)
-
There are several choices for initialization and alignment.
- For most purposes, the default initialization method (pcon_init_method=0) can be used, which uses the principal components of all the stimulus coordinates in all of the records. These can be optionally forced to be centered (pcon_init_method=-1) or not (pcon_init_method=-2); if unspecified (default), centering is determined by allow_offset. For these choices, if_initpca_rot=1 rotates the initial guess to match the data, or not. The default for if_initpca_rot is 1 unless any of dim_list_out>dim_list_in, in which case it is 0. The heuristic for not rotating if dim_list_out>dim_list_in, i.e., two or more sets of coordinates are to be knit together to construct a coordinate set with a greater number of dimensions, is that without rotation, the principal components reflect projections of the coordinates that are present in any of the records.
- Alternatively, pcon_init_method=r, r>0, specifies that the coordinates in data_in{r}{idim} are used.
- If pcon_init_method='specify', then pcon_initial_guess{idim} is an array of size [npts ids] for the initial guess, and pcon_alignment{idim}, which defaults to pcon_initial_guess, is used for the alignment at the end of each iteration. pcon_initial_guess and pcon_alignment may be omitted, in which case random values are used. To control whether the same random number seed is used on each run, use if_frozen (default is 1, which uses the same random numbers on each run).
- The solution is only unique up to rotation (and translation and reflection, if these components are allowed). The ambiguity is resolved by matching the consensus solution to the initial guess (or, pcon_alignment{idim} if separately supplied with pcon_init_method=0), as described above.
-
Under some circumstances (e.g., several solutions that are nearly equally good), the solution found by the algorithm may depend on the initialization choice. A simple strategy to check for this is to compare the results with the default pcon_init_method=0 to the results with pcon_init_method='specify' and if_frozen=0. There are two ways that this dependency can happen.
- One is that the number of overlapping stimuli is too small. For example, at least m points are required to determine a rotation and translation in an m-dimensional space; if there are fewer overlaps, then a consensus will still be found but there are many other consensus datasets that fit equally well. Note that setting aux.opts_knit.if_dim_heuristics=1 will display heuristics concerning whether there are sufficient overlaps.
- A second way is that there are a sufficient number of points, but there are several solutions that are approximately equally good.
Under these circumstances, the algorithm may get stuck in a local minimum. This possibility only occurs when there are at least three records in
data_in, as the procedure reduces to the standard Procrustes algorithm, which finds the consensus when there are only two records, is deterministic other than does rotational ambiguity.
-
The swarm option (opts_knit.if_swarm=1) can be used to automatically step through several types of initialization methods, and choose the best.
- If allow_scale=1, then the optimal solution will depend not only on the data points that overlap, but also on the data points that are unique to individual components, since these contribute to determining tthe rescaling on each iteration
Note regarding replotting a previous analysis
-
To replot a previous calculation with additional customization or to make a composite figure, proceed as follows:
data_inshould be equal to that used in the previous calculation.- aux.knit_stats should be equal to aux_out.knit_stats from the previous calculation
- aux.knit_stats_setup should be equal to aux_out.knit_stats_setup from the previous calculation
-
The following modifications are allowed in fields of knit_stats_setup:
- dataset_labels (cell array of char): dataset labels; default is data_in.sets{:}.label
- stimulus_labels (cell array of char): stimulus labbels; default is data_out.sas{1}.typenames
- shuff_quantiles (float 1-d array): quantiles to show; default is 0.01 0.05 0.5 0.95 0.99
- fig_handle (handle): figure handle to plot into; figure will be created if not supplied
- row (int): row to plot into; default is 1
- nrows (int): number of rows in the figure; default is row
-
No further calculations are done
- On return, data_out will be empty, and aux_out.fig_handle will be the figure handle
- In creating a composite figure, rows should be plotted in order from top to bottom, as plotting the bottom row triggers an equalization of the color scale. See
rs_knit_coordsets_demofor an example.
Note regarding swarm optimization
- This is enabled by setting opts_knit.if_swarm=1.
- Preliminary runs are made with several classes of initial guesses, and stopping parameters based on max_niters and max_rmstol in opts_knit.swarm
- The choice that leads to the smallest rms deviation of the aligned coordinates is recorded in aux.details{idim}.swarm, and used for a definitive run, using the stopping parameters in opts_knit
-
The classes are
- init_components: the original component datasets are used; variants choose each component dataset in succession as the initial guess, advancing to the next dataset if a stimulus is missing
- init_pca: principal components of the datasets are used, with options (mean subtraction, rotation) as described in the note regarding the Procrustes alignment algorithm; variants consist of computing the principal components from the coordinates of stimuli present in increasing numbers of the datasets
- init_random: Gaussian random varibles are used as the initial guess; the number of variants is given by opts_knit.swarm.nrand; default is 10; these random numbers do not affect the random numbers used for permutation testing
-
Results from each class are recorded in aux.details{idim}.(class_name), including
- counts: the number of variants for each class
- rms_dev_totals: the rms deviation for each example of the class
- range: the range of rms deviations for each class
- itry_min: the optimal choice within each class
- opts: the options usef for the variant with the lowest rms deviation
Note regarding rays
- The
ray structuredescribes relationships among the simulus coordinates:rays, i.e., sets of stimuli that lie along an axis or a ray from the origin,rings, stimuli that lie at an approximately equal distance from the origin, and nearest neighbors. It is only created if there is a valid set of stimulus coordinates.
See also
rs_align_coordsets, rs_aux_customize, rs_check_coordsets, rs_findrays, PSG_ALIGN_COORDSETS, PSG_KNIT_STATS, PSG_REMNAN_COORDSETS, PSG_COORD_PIPE_UTIL, overlap_heuristics, procrustes_consensus, PSG_ALIGN_STATS_PLOT.
Source code in src/rs_knit_coordsets.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 | |
rs_plot_style(coords, plotstyle, opts)
[handles,plotstyles_used,opts_used]=rs_plot_style(coords,plotstyle,opts) plots a set of points into the current axis
The data may be either 2D or 3D. Marker type, marker size, line style, line thickness, and alpha blending, may be specified. Possible conflicts or unsupported properties are handled.
Input arguments:
-
coords(float 2-D array) –data to plot, 2 columns for a 2D plot, 3 columns for a 3D plot
-
plotstyle(struct) –specification of plotting style, may be omitted, with fields
marker(char) – marker type; one of {'.','o','x','+','*','s','d','v','^','<','>','p','h'}; default is '.'markersize(int) – marker size; default is 6linestyle(char) – line style; one of {'-',':','-.','--',','none'}; default is 'none'linewidth(int) – width of lines and marker edges; default is 1color(char or float 1-D array) – color of points, lines, and marker edges, can be any Matlab color specifier or an (r,g,b) triple; default is 'k' (black)color_fill(char or fload 1-D array) – color of marker interior if marker is filled; default is plotstyle.color;filled(int) – 1 to filled marker, 0 for unfilled; default is 0alpha(float) – alpha-blending (transparency); defaults to 1 (opaque)
-
opts(struct) –how to resolve conflicts (see note below regarding graphic hints), may be omitted, with fields
if_alpha_color_line(int) – 1 if line color property allows for alpha as fourth component, 0 if not, -1 to determine from hints; default is -1if_alpha_color_line_marker(int) – 1 if marker edge color property allows for alpha as fourth component, 0 if not, -1 to determine from hints; default is -1if_alpha_scatter_marker_edge(int) – 1 if MarkerEdgeAlpha is a property of Scatter, 0 if not, -1 to determine from hints; default is -1if_alpha_scatter_marker_face(int) – 1 if MarkerFaceAlpha is a property of Scatter, 0 if not, -1 to determine from hints; default is -1
Output arguments:
-
handles(struct) –structure of handles to the plot and components, with fields
line(struct) – handle of the graphics line object used for the line connecting points; may be emptymarkers(struct) – handle of the graphics object for the plotted points, may be a line or scatter objectscatter(struct) – handle of the graphics scatter object for the plotted points; may be emptylegend(struct) – handle to graphics object (line or scatter) that can be used for a legend; will be either handles.line or handles.scatter and will not be empty
-
plotstyles_used(struct) –plot styles with defaults filled in
-
opts_used(struct) –opts, with defaults filled in; see note below regarding graphic hints
General notes
- Plotting will be into current axis if available; otherwise a new axis will be created.
- Axis hold state will be 'on' after plotting.
Note regarding graphic hints
- Capabilities for alpha-blending may be version-dependent, and should be indicated during installation by customizing
rs_graphic_hints - An entry of -1 (default) in 'opts' uses
rs_graphic_hintsto determine the capability. - If
rs_graphic_hintsis absent, the present, and if not, by attempting to set an alpha property - At run-time, these hints may be overrridden by a 1 (capability present) or a 0 (capability absent) in a field of 'opts'.
- If an attempt to use transparency fails, then the corresponding field of 'opts_used' is set to 0, and a essage is generated in opts_used.msgs
See also: rs_plot_style_test, rs_graphic_hints.
Source code in src/rs_plot_style.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
rs_read_choicedata(fullname, aux)
[data_comp,aux_out]=rs_read_choicedata(fullname,aux) reads a single choice file and validates entries
The choice file may be triadic or tetradic, as determined by the number of columns in the choices variable of the data file: 5 columns if triadic, 6 columns if tetradic
Each row of the variable 'responses' holds responses from one or more presentations of a single comparison. Comparisons may be repeated in other rows, and a comparison may also be repeated with a separate indexing (e.g., s1 and s2 may be reversed).
Important note: The standard convention in the choice file is to count the number of times the first comparison is judged to be more different than the second; in 'data_comp', the opposite convention is used.
This conversion is made automatically and logged.
Input arguments:
-
fullname(char or singleton char array) –full file name with path; if empty, it will be requested interactively. File names must contain the string '_coords'. See note below regarding setup files.
-
aux(struct) –a structure, can be omitted, with fields
opts_read(struct) – options for reading, can be omitted, with fieldsif_gui(int) – 1 to use graphical interface to request data file name if 'fullname' is empty, 0 to use console; default is 1; see note below regarding customizationif_log(int) – 1 to log progress, 0 to omit; default is 1; see note below regarding customizationdata_fullname_def(char) – prompt for data file if 'fullname' is empty; see note below regarding customizationui_filter(char) – file name filter that appears in graphical user interface when if_gui=1; defaults to '_choices'; see note below regarding customizationif_consolidate(int) – 1 to consolidate equivalent triadic and tetradic judgments into a single line, 0 does not; default is 1
opts_check(struct) – options for consistency checking, with fieldif_warn(int) – 1 to show warnings when datasets are checked for consistency, 0 to suppress; default is 1
Output arguments:
-
data_comp(int 2-D array) –Choice data, with each row containing the data from a single kind of comparison
-
first 3 or 4 columns: indexes into the stimuli used for the comparison
- triadic: col 1 is reference, col 2 is s1, col 3 is s2, comparisons are (ref,s1) and (ref,s2)
- tetradic: cols 1-4 are s1-s4, comparisons are (s1,s2) and (s3,s4)
-
next column: number of times the first difference was judged more similar than the second difference
- final column: number of times the comparison was made
-
-
aux_out(struct) –auxiliary outputs and parameter values used, with fields
typenames(cell array) – stimulus labels, corresponding to the indices used in the first 3 or 4 columns of choices. The order is unchanged from the order in the data file.warnings(char) – warnings generated during consistency checkwarn_bad(int) – number of warnings that prevent further processingopts_read(cell array of struct) – opts_read{1} is aux.opts_read, with defaults filled inopts_check(struct) – aux.opts_check, with defaults filled in
Note regarding customization
-
The defaults for the following parameters can be set by editing the line containing generic.opts_read.[param_name] in
rs_aux_defaults_define, running it once, and saving the workspace as rs_aux_defaults.mat.- if_gui
- if_log
- data_fullname_def ('_coords' will be replaced by '_choices' at run time)
- coord_string
- type_class_aux
See also: rs_aux_customize, rs_check_coordsets, PSG_READ_COORDDATA.
Source code in src/rs_read_choicedata.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
rs_read_coorddata(fullname, aux)
[data_out,aux_out]=rs_read_coorddata(fullname,aux) reads a coordinate file into a dataset structure with a single record
This is the preferred method for bringing coordinates from a single file into a dataset structure suitable for display and geometrical analysis.
- For files generated by analysis of similarity judgments via [??how to refer to Python package], this will also import the goodness-of-fit data.
- For multiple coordinate sets collected with the same experimental paradigm, use
rs_get_coordsets, or use this routine and combine multipledataset structuresinto a singledataset structurewithrs_concat_coordsets. - A
ray structurewill be created. - To create a
coordinate structurebased on aquadratic form model, also users_get_coordsets. - For
binary texture domaindata with symmetry augmentation, users_get_coordsets. - To import coordinates generated externally or that exist as arrays rather than in a file, use
rs_import_coordsets.
Input arguments:
-
fullname(char or singleton char array) –full file name with path; if empty, it will be requested interactively. File names must contain the string '_coords'. See note below regarding setup files.
-
aux(struct) –a structure, can be omitted, with fields
opts_read(struct) – options for reading, can be omitted, with fieldsif_gui(int) – 1 to use graphical interface to request data file name if 'fullname' is empty, 0 to use console; default is 1; see note below regarding customizationif_log(int) – 1 to log progress, 0 to omit; default is 1; see note below regarding customizationdata_fullname_def(char) – prompt for data file if fullname' is empty; see note below regarding customizationui_filter(char) – file name filter that appears in graphical user interface when if_gui=1; defaults to '_coords';see note below regarding customizationtype_coords(float 2-D array) – stimulus coordinates to use for non-reserved domain names, one row for each stimulus; default is emptytype_coords_def(char) – stimulus coordinates to use if type_coords is unspecified or empty; options are 'none', 'zeros', 'ones', or 'eye', seers_import_coordsets; default is 'none'; seers_import_coordsetsfor further details and how to customizedomain_list_def(cell array) – paradigm names for generic domain experiments; default is {'cars','tools','dwellings'}; determined by customization during installparadigm_type_def(char) – default paradigm type; default is determined by customization during installcoord_string(char) – a string in a data file name that delineates the end of the domain name; defaults to '_coords'setup_fullname_def(char) – prompt for setup file namesetup_suffix(char) – suffix added to paradigm name to create the setup file name; default is 'S'type_class_aux(char) – a specified domain name and type_classpermutes(struct) – typically omitted; each field is a suggested ray permutation for the corresponding paradigm name, e.g., permutes.bgca=[2 1 3 4] specifies a reordering of the rays for paradigm 'bgca'permutes_ok(int) – typically omitted; 1 to accept suggested ray permutation, 0 to keep standard order; default is 1; see note below regarding customizationif_uselocal(int) – typically omitted; 0 to use options in rs_aux_defaults, 1 is reserved for maintenance; default is 0
Options related to stimulus coordinates, domains, and setup files (see notes below)
Options for internal use and maintenance
opts_rays(struct) – options for identifying rays, may be omitted; seers_findraysfor detailsopts_check(struct) – options for consistency checking, with fieldif_warn(int) – 1 to show warnings when datasets are checked for consistency, 0 to suppress; default is 1
Output arguments:
-
data_out(struct) –dataset structurewith one record, and fieldsds(singleton cell array) –coordinate structure, ds{1}{idim} is an array of [nstims idim] of coordinates for the sole recordsas(singleton cell array) –stimulus metadata structure, sas{1} is the stimulus metadata for the sole recordsets(singleton cell array) –set metadata structure, sets{1} is the response metadata for the sole record
-
aux_out(struct) –auxiliary outputs and parameter values used, with fields
warnings(char) – warnings generated during consistency checkwarn_bad(int) – number of warnings that prevent further processingrayss(cell array of struct) – rayss{1} is theray structurefor the sole recordopts_read(cell array of struct) – opts_read{1} is aux.opts_read, with defaults filled inopts_rays(cell array of struct) – opts_rays{1} are the options used for creating theray structurefor the sole recordopts_qpred(cell array of struct) – empty (included for compatibility withrs_get_coordsets)syms_list(struct) – empty (included for compatibility withrs_get_coordsets)opts_check(struct) – aux.opts_check, with defaults filled in
Note regarding domain names, stimulus coordinates, and setup files
-
The domain name is determined from the data file name based on the string preceding '_coords' (or, opts_read.coord_string, if customized). This in turn determines how stimulus coordinates are specified.
- For non-reserved domain names (opts_read.type_class_aux, or any domain in opts_read.domain_list_def), stimulus coordinates are specified by 'type_coords' and no setup file is used.
- Other domain names are reserved, and stimulus coordinates are specified by a 'setup file', whose suggested name is constructed from the data file name up to the string preceding opts_read.coord_string, and appending opts_read.setup_suffix
-
The domain name is also used to determine a 'type_class', which is used internally. This is carried out in psg_coorddata_parsename, as follows:
- The domains 'faces*' are reserved; type_class is faces_mpi; used with a setup file
- The domain 'irgb' is reserved; type_class is 'irgb'; used with a setup file
- The domain 'mater' is reserved; type_class is 'mater'; used with a setup file
- The domain opts_read.type_class_aux is NOT reserved; type class is type_class_aux; no setup file used
- Any domain that is listed in opts_read.domain_list_def is NOT reserved; type class is 'domain'; no setup file used
-
Otherwise, type_class is set to opts_read.type_class_def, ('btc' unless customized); used with a setup file
-
When a
dataset structureis written byrs_write_coordsets, the setup file information, if any, will be embedded. When that file is read in and an embedded setup file is detected, no setup file is requested. - Also see note below regarding customization
Note regarding customization
-
The defaults for the following parameters can be set by editing the line containing generic.opts_read.[param_name] in
rs_aux_defaults_define, running it once, and saving the workspace as rs_aux_defaults.mat.- if_gui
- ui_filter
- if_log
- data_fullname_def
- setup_fullname_def
- domain_list_def
- setup_suffix
- permutes_ok
- coord_string
- type_class_aux
See also: rs_import_coordsets, rs_aux_customize, rs_findrays, rs_check_coordsets, PSG_READ_COORDDATA, PSG_MAKE_SETSTRUCT, PSG_FINDRAYS_SETOPTS, PSG_FINDRAYS.
Source code in src/rs_read_coorddata.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
rs_save_figs(fullname, whichfigs, opts)
rs_save_figs(whichfigs,whichfigs,opts) writes one or more open figures to a fig file
Input arguments:
-
fullname(char) –file name, with path; if no figure handle is given, then all figures are saved, and '_fig_n' is appended, where n is sequentially incremented
-
whichfigs(handle or array of handles or char) –a figure handle, a list of handles, or 'all', or empty, or omitted; if empty, current figure; default is [] (empty)
-
opts(struct) –
See also: zpad, rs_save_mat.
Source code in src/rs_save_figs.m
rs_save_mat(fullname, s, opts)
opts_used=rs_save_mat(fullname,s,opts) writes the fields of a structure to a mat file
Input arguments:
-
fullname(char) –file name, with path; .mat will appended if necessary
-
s(struct) –a structure whose fields are to be saved
-
opts(struct) –options, with field
ver(char) – format for saving; default is '-v7'
Output arguments:
-
opts_used(struct) –opts, with defaults filled in
See also: PSG_SAVE_MAT.
Source code in src/rs_save_mat.m
rs_showpipeline(pipeline, opts)
depth_max=rs_showpipeline(pipeline,opts)
is a utility to show the pipeline field of a set metadata structure
The pipeline field tracks the processing steps leading to a dataset structure.
It may have subfields 'sets', indicating a single dataset that was modified to create this structure;
'sets_combined', indicating a group of datasets that were combined to create this structure;
'opts', the options used in the processing path; and
'file_list', the names of the files containing the data.
Input arguments:
-
pipeline(struct) –the 'pipeline' field of a `set metadata structure
-
opts(struct) –options, can be omitted, with fields
depth_limit(int) – maximum depth to show; defaults is Infbreadth_limit(int) – maximum breadth (number of branches) to show if sets_combined is present; default is Infverbosity(int) – 0 (brief), 1, or 2; default is 1fields_expand(cell array of char) – names of fields to expand; defaults to {'opts','file_list'}; other fields that could be added are 'sets','sets_combined'
Output arguments:
-
depth_max(int) –maximum depth reached (cannot exceed opts.depth_limit)
See also: PSG_SHOWPIPELINE.
Source code in src/rs_showpipeline.m
rs_symumi_choicedata(data_comp, aux)
[su,aux_out]=rs_symumi_choicedata(data_comp,aux) analyzes a set of triadic choices to determine the symmetry index and the ultrametric index (measures of consistency with symmetry and the ultrametric inequality) as described in Ordinal Characterization of Similarity Judgments on arXiv and Mathematical Neuroscience and Applications
The analysis is carried out for a range of criteria for the triads to include, and for Dirichlet fits to the choice probability distribution based on all triads (in 'su.global'), or only the triads that meet threshold criteria (in 'su.private'). See note below regarding threshold criteria and global vs. private analyses.
Input arguments:
-
data_comp(int 2-D array) –Triadic choice data, with each row containing the data from a single kind of comparison
- col 1 is reference, col 2 is s1, col 3 is s2
- col 4: number of times the first difference was judged more similar than the second difference
- col 5: number of times the comparison was made
-
aux(struct) –a structure, can be omitted, with fields
opts_symumi(struct) – options for analysis, with fieldsif_log(int) – 1 to log progress, 0 to omit; default is 1h_fixlist(float 1-D array) – values for discrete component 'h', should include zero and be in ascending order, default is [0 0.001 0.01 0.1]ntriplets_min(int) – minimum number of triplets for an analysis, default is 3if_private(int) – 1 to also do calculations with Dirichlet fits only to the triads that meet threshold criteria, 0 to omit; default is 0if_frozen(int) – random number control; 1 for same numbers every run, 0 for different random numbers each run, negative integer for a fixed seed each run, default is 1a_limits(float) – allowed range for 'a' (shape), when fitting only 'a', default is [10^-2 10^2]a_optimset(struct) – non-default optimizations parameters for fitting 'a', withfminbnd, default is struct()ah_optimset(struct) – non-default optimizations parameters for fitting 'a' and 'h', withfminsearch, default is struct()if_fast(int) – use hard-coding for partitions, skip calls to filldefault, default is 1if_check(int) – 1 to compare methods, -1 to log, treated as 0 if if_fast=1, default is 0tol(float) – tolerance for checking consistency, ignored if if_check is 0, default is 10^-5if_vec(int) – if present, use vectorized method, default is abesentif_partition(struct) – if present, use general calculation of psg_ineq_logic, default is absent
Plotting and replotting
Options for statistics and shuffles
Options to control optimization details
Options for internal use and maintenance
opts_check(struct) – options for consistency checking, with fieldif_warn(int) – 1 to show warnings, 0 to suppress; default is 1
Output arguments:
-
su(struct) –analysis results, a structure with fields
summary(cell 1-D array) – summary of analysis of symmetry and ultrametric indices, organized by fraction of triplets retained; summary{1} is analysis with fixed value of 'h', summary{2} is analysis with 'h' fitted; summary{:}.sym and summary{1}.umi contain the following subfieldsparams(struct) – params.a and params.h are the Dirichlet parametersapriori_vals(float) – a priori value of the indexah_llr(float) – log likelihood ratio for the Dirichlet fit to the choice probability distributionthr_type(cell 1-D array) – statistics for threshold type 1 (min), 2 (max), 3 (avg)means_per_set_adj(float 2-D array) – means_per_set_adj(ithr,[1 2 3]) is the mean index for each threshold type, adjusted by log(h) for umi indexeb_stds(float 2-D array) – 1 s.d. error bar sizefrac_keep_list(float 1-d array) – fraction of triplets kepttally_table(int 2-D array) – tally_table(ithr,[1 2 3]) is the threshold, count of triads, count of trialsthr_ptr_use(int 1-D array) – pointers into thresholds (tally_table(:,1)), corresponding to values in frac_keep_list
global(struct) – detailed likelihood analysis for symmetry and ultrametric indices, based on Dirichlet fits to choice probabilities for all triadic judgments, with fieldsa(int 3-D array) – a(1,1:2,ih) is the fitted Dirichlet shape parameter 'a' and log likelihood per trial assuming h=h_fixlist(ih)ah(int 2-D array) – ah(1,1:3) are the jointly fitted Dirichlet parameters 'a' and 'h' and log likelihood per trial for threshold value dirichlet.tallies(ithr,1)sym_hfixed(cell 2-D array) – sym_hfixed{isv,ithr_type}(ithr,:,ih) is sum (isv=1) or the variance (isv=2) of the symmetry index, for threshold type ithr_type, threshold value dirichlet.tallies(ithr,1), assuming h=h_fixlist(ih)sym(cell 2-D array) – sym{isv,ithr_type}(ithr,:) is the sum (isv=1) or the variance (isv=2) of the symmetry index, for threshold type ithr_type, threshold value dirichlet.tallies(ithr,1), with 'a' and 'h' jointly fittedumi_hfixed(cell 2-D array) – umi_hfixed{isv,ithr_type}(ithr,:,ih) is the sum (isv=1) or the variance (isv=2) of the ultrametric index, for threshold type ithr_type, threshold value dirichlet.tallies(ithr,1), assuming h=h_fixlist(ih)umi(cell 2-D array) – umi{isv,ithr_type}(ithr,:) is the sum (isv=1) or the variance (isv=2) of the ultrametric index, for threshold type ithr_type, threshold value dirichlet.tallies(ithr,1), with 'a' and 'h' jointly fitted
private(struct) – detailed likelihood analysis for symmetry and ultrametric indices, based on Dirichlet fits only to choice probabilities that meet the threshold criterion, with fieldsa(cell 1-D array) – a{ithr_type}(ithr,1:2,ih) are the fitted Dirichlet shape parameter 'a' and log likelihood per trial for threshold type and threshold value dirichlet.tallies(ithr,1), assuming h=h_fixlist(ih)ah(cell 1-D array) – ah{ithr_type}(ithr,1:3,ih) are the jointly fitted Dirichlet parameters 'a' and 'h' and log likelihood per trial for threshold type ithr_type and threshold value dirichlet.tallies(ithr,1)sym_hfixed(cell 2-D array) – sym_hfixed{isv,ithr_type}(ithr,:,ih) is the sum (isv=1) or the variance (isv=2) of the symmetry index, for threshold type ithr_type, threshold value dirichlet.tallies(ithr,1), assuming h=h_fixlist(ih)sym(cell 2-D array) – sym{isv,ithr_type}(ithr,:) is the sum (isv=1) or the variance (isv=2) of the symmetry index, for threshold type ithr_type, threshold value dirichlet.tallies(ithr,1), with 'a' and 'h' jointly fittedumi_hfixed(cell 2-D array) – umi_hfixed{isv,ithr_type}(ithr,:,ih) is the sum (isv=1) or the variance (isv=2) of the ultrametric index, for threshold type ithr_type, threshold value dirichlet.tallies(ithr,1), assuming h=h_fixlist(ih)umi(cell 2-D array) – umi{isv,ithr_type}(ithr,:) is the sum sum (isv=1) or the variance (isv=2) of the ultrametric index, for threshold type ithr_type, threshold value dirichlet.tallies(ithr,1), with 'a' and 'h' jointly fitted
dirichlet(struct) – Dirichlet fits for lowest and highest thresholds for number of trials in a triad, with fieldstallies(int 2-D array) – tallies(:,1) is threshold number of trials in a triad; tallies(:,2) is number of triads meeting the threshold; tallies(:,3) is number of trials in those triadscolumns_tallies(cell 1-D array) – labels for columns of talliesh_fixlist(float 1-D array) – list of values assumed for the discrete component, first element is 0a(int 3-D array) – a(ithr,1,ih) is fitted value of Dirichlet shape parameter 'a' for triads meeting threshold of tallies(ithr,1) and assuming h=h_fixlist(ih); a(ithr,2,ih) is corresponding log likelihood per trialcolumns_a(cell 1-D array) – labels for columns of aah(int 2-D array) – ah(ithr,1:2) are jointly fitted values of Dirichlet shape parameter 'a' and discrete parameter 'h' for triads meeting threshold of tallies(ithr,1); ah(ithr,3) is corresponding log likelihoood per trialcolumns_ah(cell 1-D array) – labels for columns of ah
meta(struct) – labels for dimensions of the variables in su.global and su.privatecounts(struct) – summary of the input data, a structure with fieldsntrials_found(int) – number of individual judgmentsntriads_found(int) – number of distinct triads judgednstims_found(int) – number of different stimuliunique_stims(int 1-D array) – list of unique stimuli
tallies(cell 1-D array) – summary of the data used for each calculation in global and private, where tallies{ithr_type}(ithr,:) is [threshold pointer, number of triplets used, number of trials used] for threshold type ithr_type (1: min, 2: max, 3: avg, see note below regarding thresholds); the threshold value corresponding to ithr is dirichlet.tallies(ithr,1)
Symmetry and ultrametric indices
Dirichlet fits
-
aux_out(struct) –auxiliary outputs and parameter values used, with fields
warnings(char) – warnings generated during consistency checkwarn_bad(int) – number of warnings that prevent further processingopts_symumi(struct) – aux,opts_symumi with defaults and values usedopts_check(struct) – aux.opts_check, with defaults filled inopts_dirfit_a(struct) – options used forrs_dirfit_choicedatafor fitting Dirichlet parameter 'a'opts_dirfit_ah(struct) – options used forrs_dirfit_choicedatafor fitting Dirichlet parameters 'a' and 'h'opts_triplike(struct) – options used forpsg_umi_triplikefig_handles(cell 1-D array) – handles to figures for summary plot ((present only if if_plot>=1)fig_handle_detailed(handle) – handle to figure for detailed plot (present only if if_plot=2)
Note regarding thresholds and global vs. private analyses
- Triplets are screened by a threshold criterion based on the number of trials before inclusion in the calculation of the symmetry and ultrametric indices.
- The criterion is applied three ways: to the minimum numnber of trials of the three triads in a triplet, the maximum number, and the average number
- For the 'global' analysis, the selected triplets are used to calculate the symmetry and ultrametric indices, but all triads are used to calculate the Dirichlet parameters
- For the 'private' analysis, the selected triplets are used to calculate the symmetry and ultrametric indices and also to calculate the Dirichlet parameters
- The 'private' analysis is substantially slower than the 'global' analysis, and values are of the indices are typically similar; it is only enabled by setting opts_symumi.if_private=1
Triads, trials, and triplets
- A triad is a set of three stimuli used in a triadic judgment: one stimulus is the reference, and the other two are the comparison stimuli
- A trial is a single judgment of similarity for a given triad
- A triplet is a set of three triads built out of the same three stimuli, in which each stimulus in turn serves as the reference
- The number of trials in a triplet is the sum of the number of trials in its three triads
See also: rs_dirfit_choicedata, rs_addtree_choicedata, PSG_TRIPLET_CHOICES, loglik_beta_discrete.
Source code in src/rs_symumi_choicedata.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 | |
rs_typenames2colors(typenames, aux)
[rgb,symb,cvecs,aux_out]=rs_typenames2colors(typenames,aux) is a utility that assigns a display color and symbol to a set of stimulus labels. Stimulus coordinates are extracted from 'typenames', and mapped to a color and plotting symbol detailed below. The color is determined by the direction from the origin and the symbol is determined by the sign(s) of the coordinates.
Input arguments:
-
typenames(char or cell array of char) –one or more stimulus labels; see note below regarding parsing of typenames into coordinates
-
aux(struct) –auxiliary input, may be omited, with field
opts_tn2c(struct) – options controlling mapping of coordinates to colors and symbols, with fieldscoord_lets(char) – letter tokens to be regarded as coordinates; default is 'abcdefghij'; avoid including m, p, z. This is ignored if the paradigm type is one of the reserved paradigms. Specifying this parameter will remove the default color assignments and thus require specification of color assignments in opts_tn2c.colorscolors(struct) – custom color assignments for the coordinates in coords_lets, consisting of a structure with fields labeled by coord_lets, each containing an r,g,b triple or other valid color designator; defaults are:- a: red [1 0 0]
- b: blue [0 0 1]
- c: green [0 1 0]
- d: yellow [1 1 0] * 0.75
- e: purple (red+blue)/2
- f: cyan (blue+green)/2
- g: lime (green+yellow)/2
- h: orange (yellow+red)/2
- i: light gray [1 1 1] * 0.75
- j: dark gray [1 1 1] * 0.3
colors_nomatch(color specifier) – color to be used if coordinates cannot be found; default is [0 0 0];if_color_arith(int) – 1 to enable averaging of colors if typenames contains several strings, 0 to use color of point that is maximal distance from origin; default is 1symbs(struct) – plotting symbol to be assigned based on signs of coordinates; defaults are:- z: 'o', if all coordinates are zero
- m: '*', if at least one coordinate is negative and none are positive
- p: '+', if at least one coordinate is positive and none are negative
- pm: 'v' (downward triangle), if coordinates have mixed signs, with a positive occurring first
- mp: '^' (upward triangle), if coordinates have mixed signs, with a negative occurring first
symbs_nomatch(char) – symbol to be assigned if no coords can be found, default is '.'if_usetypenames(char) – 1 to decode typenames to determine coordinates; 0 to cosider typenames as a 2d float array of coordinates; default is 1paradigm_type(char) – paradigm type, typically from data.sets{:}.paradigm_type; default is 'unknown', which will result in colors and symbols assigned as described here.paradigms_reserved(cell array of char) – paradigm types whose colors and symbols are assigned by 'psg_typenames2colors' defaults to {'btc','faces'}; see note below regarding reserved paradigm types.
Colors
Symbols
Overall behavior
Output arguments:
-
rgb(float 1-D array) –the assigned rgb color triplet
-
symb(char) –the plotting symbol
-
cvecs(float 2-D array) –decoded coordinates, with each row corresponding to an element of typnames, and consisting of length(coord_lets) coordinate values, with NaN if coordinate is not found
-
aux_out(struct) –auxiliary outputs and parameter values used, with field
opts_tn2c(struct) – aux.opts_tn2c, with defaults filled in
Note regarding parsing of typenames into coordinates
- The typenames argument is a string, or a a cell array of strings; each of which is parsed into coordinates.
- These strings consist of a coordinate axis designator, typically [a-j] ynless modified by opts_tn2c.coord_lets, followed by a numeric quantity.
- The numeric quantity consists either of string of digits (assumed to represent a positive quantity), or a string of digits preceded by p or m (to represent a positive or negative quantity), or z (followed by any numbers), indicating zero.
- The string can also contain a decimal point,'+', or '-', intrepreted in the standard fashion. The sign is multiplied by the sign designated by a preceding 'p' or 'm' if present.
-
Examples, assuning that coords_lets has the default value of 'abcdefghij':
- 'z' indicates the origin, i.e., 0 on all coordinate axes
- 'a3b5cm1' indicates (3,5,-1) on the first three axes
- 'cm52' indicates -52 on the c (third) axis
- 'bp4 hm36' indicates +4 on the b (second) axis, -36 on the h (eighth) axis
- 'j17dm3' indicates -3 on the d (fourth) axis, 17 on the j (tenth) axis,
- 'am1.4' and 'am-1.4' indicate -1.4 on the a (first) axis but 'am-1.4' indicates +1.4 on the a axis
-
All of the strings in typenames are parsed in his fashion. To assign color:
- If ony one axis is present among typenames, then its color is used.
- If more than one axis is present anong the typenames, and color values are given as rgb triples, and if_color_arith=1, then colors are weighted by the magnitudes.
- Otherwise the color of the axis that has the largest magnitude coordinate will be used, with ties broken by order of axes.
Note regarding reserved paradigm types
- For certain reserved paradigm types, color and symbol assignments deviate from the behavior described here and are controlled by psg_typenames2colors.
-
paradigm_type='btc': this refers to stimuli from the
binary texture domain. Symbols are assigned as described above. 'cvecs' are decoded based on coord_lets='gbcdetuvwa', and typename strings such as 'gm0461' are interpreted as a value of 0.461 on the g (first) axis. Colors are assigned to coordinates as follows:- g (gamma)->gray
- b,c (cardinal beta) -> dark and light blue
- d,e (diagonal beta) -> dark and light green
- t,u,v,w (theta): -> yellows and browns
- a (alpha) -> red
-
paradigm_type='faces': this refers to stimuli from the
MPI faces domain. Strings in typenames should correspond to file names from the MPI archive, which are of the form '132_y_f_n_a' ('[individual][age][gender]_[exemplar]'). Colors and symbols are assigned as below; 'cvecs' is returned empty.- gender: f->red [1 0 0], m->blue [0 0 1]
- age: y,m,o -> dark, medium, light (blend gender color with [.75 1 .75], weighing gender color by 0.4 (y), 0.7 (m), or 1.0(o))
- expression: neutral-> 'x' for set A, '+' for set b; angry->'*', sad -> 'v' (downward triangle), happy -> '^' (upward triangle), fright-> 'h' (hexagon), disgust -> 'p' (pentagon)
-
The list of default reserved paradigms can be changed by adding a line defining generic.opts_tn2c.paradigms_reserved in
rs_aux_defaults_define, running it once, and saving the workspace as rs_aux_defaults.mat.
See also: rs_disp_enh_coordsets.
Source code in src/rs_typenames2colors.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
rs_vara_coordsets(data_in, groupings, aux)
[vara_stats,aux_out]=rs_vara_coordsets(data_in,groupings,aux) does an analysis of variance across groups of dataset structures via shuffling by trials, and provides and displays statistics
Basic strategy: records are grouped, consensus is found within each group, and the variance around the consensus is computed. Then, records are shuffled between groups. The shuffling can also be constrained by assigning tags to each dataset, e.g., according to the subject ID, and only shuffling within records that have the same tag. For each shuffle, the variance around the consensus within each group is again calculated, and compared tothat of the original data.
Note that in contrast to rs_knit_coordsets, in which shuffling permutes the coordinates of the stimuli within a record, here the shuffling permutes the records across groups.
Global consensus and consensus of groups are not returned; these can be computed with rs_knit_coordsets.
Input arguments:
-
data_in(struct) –dataset structureto be processed, with fieldsds(cell array) –coordinate structure, ds{k}{idim} is an array of [nstims idim] of coordinates for the kth recordsas(cell array) –stimulus metadata structure, sas{k} is the stimulus metadata for the kth recordsets(cell array) –set metadata structure, sets{k} is the response metadata for the kth record
-
groupings(struct) –structure specifying assignment of records to groups, and, optionally, tags to restrict shuffling
gps(int 1-D array) – gps(k) is the group assignment of record k, an integer from 1 to the number of groups (ngps); All groups must have at least one record.tags(int 1-D array) – tags(k) is the tag assigned to record k. If non-empty, shuffles will only swap a record with a record of the same tag. Defaults to empty ([]),
-
aux(struct) –auxiliary inputs, may be omitted, with fields
opts_vara(struct) – options for the variance analysis, with fieldsallow_offset(int) – 1 to allow translational offset, 0 does not allow; default is 1allow_scale(int) – 1 to allow scaling of each dataset into the consensus, 0 does not allow; default is 0allow_reflection(int) – 1 to allow reflection, 0 does not allow; default is 1if_normscale(int) – 1 to normalize consensus to size ofdata_in(determined by geometric mean of scale factors for each dataset), 0 does not, has no effect if allow_scale=0; default is allow_scaleif_stats(int) – 1 to do statistics of variance explained, 0 does not; default is 1if_exhaust(int) – 1 to attempt to use exhaustive set of shuffles, otherwise will use nshuffs random shuffles if number required is > nshuffs_nax; default is 1nshuffs(int) – number of shuffles to use; fewer will be made if if_exhaust=1 and number needed for exhaustive list is less than nshuffs_exhaust_max; default is 500 if if_stats=1, 0 if if_stats=0; see note below regarding statistics and plotsshuffs_supplied(int 2-D array) – if nonempty, user-supplied shuffles to be used; if empty, shuffles will be created according to if_exhaust and nshuffs; default is empty ([]); shuffs_supplied(ishuff,k) is the record used in place of original record k on shuffle ishuffnshuffs_max(int) – maximum number shuffles that can be generated; if if_exhaust=1 and number of exhaustive shuffles exceeds this value, random shuffles will be used instead; default is 10^4if_frozen(int) – random number control for shuffles and initialization; 1 for same numbers every run, 0 for different random numbers each run, negative integer for a fixed seed each rundim_max_in(int) – maximum dimension of data_in.ds to use; default is maximum available across all datasetsdim_list_in(int 1-D array) – list of dimensions to use from data_in.ds, must be unique; default is [1:dim_max_in]dim_aug(int) – number of dimensions to add for consensus datasets; default is 0; see note below regarding Procrustes consensus algorithmdim_list_out(int 1-D array) – list of dimensions for consensus datasets, must be same length as dim_list_in, no less than corresponding elements of dim_list_in, and unique; default is [1:dim_list_in]+dim_augif_plot(int) – 1 to plot statistics, 0 does not; default is if_statsshuff_quantiles(float 1-D array) – quantiles to plot; default is [0.01 0.05 0.5 0.95 0.99]if_remove_path_label(int) – 1 to remove path from filename when used as a label (in data_in.sets{:}.label), 0 does not; default is 1vara_stats(struct) – include to replot a previous analysis, otherwise omit; see note below regarding replottingvara_stats_setup(struct) – include to replot a previous analysis, otherwise omit; see note below regarding replottingif_log(int) – 1 to log progress, 0 to suppress; default is 1pcon_init_method(int or char) – typically omitted; default is 0, leading to 'pca' method for initializingprocrustes_consensus; see note below regarding Procrustes consensus algorithmif_initpca_rot(int) – typically omitted, default is 1 unless any of dim_list_out>dim_list_in; see note below regarding Procrustes consensus algorithmmax_iters(int) – maximum number of iterations for Procrustes consensus; default is 1000; see note below regarding Procrustes consensus algorithmmax_rmstol(int) – maximum change ofcoordinates for consensus solution; default is 10^-5; see note below regarding Procrustes consensus algorithmpcon_initial_guess(cell array) – specified initial guess for Proccrustes minimization, typically omitted; see note below regarding Procrustes consensus algorithmpcon_alignment(cell array) – specified alignment for Procrustes minimization, typically omitted; see note below regarding Procrustes consensus algorithm default is 1; see notes below regarding statistics and Procrustes consensus algorithm
Transformations
Statistics and shuffles
Dimension selection
Plotting and replotting
Logging and optimization
opts_check(struct) – options for consistency checking, with fieldif_warn(int) – 1 to show warnings when datasets are checked for consistency, 0 to suppress; default is 1
opts_align(struct) – options for alignment of data, typically omittedsa_pooled(struct) – include to avoid recalculation of alignment, otherwise omit; see note below regarding recalculation of alignmentdata_align(struct) – include to avoid recalculation of align ment, otherwise omit; see note below regarding recalculation of alignment
Output arguments:
-
vara_stats(struct) –statistics and analysis parameters, detailed in note below regarding statistics and plots
-
aux_out(struct) –auxiliary outputs and parameter values used
warnings(char) – warnings generated during consistency checkwarn_bad(int) – number of warnings that prevent further processingopts_vara(struct) – aux.opts_vara, with defaults filled inopts_check(struct) – aux.opts_check, with defaults filled inopts_pcon(cell array of struct) – opts_pcon{idim} are the options used in Procrustes alignment for model dimension idimopts_align(struct) – aux.opts_align, with defaults filled invara_stats_setup(struct) – parameters extracted from aux.opts_vara, along with the additional fields below; see note below regarding replotting a previous analysisnsets(int) – number of records indata_innstims(int) – number of stimulidataset_labels(cell array of char) – dataset labels, from data_in.sets{:}.labelstimulus_labels(cell array of char) – stimulus labels, from data_out.sas{1}.typenames
fig_handle(handle) – handle to figure created (present only if statistics are plotted)
General notes
- For all records with data_in.sets{k}.type='data', the strings in data_in.sets{k}.paradigm_type must agree.
Note regarding statistics and plots
- If aux.opts_vara.if_stats=1, statistics regarding variances between individual sets and within-group consensus, and between individual sets and the global consensus, are returned in vara_stats, along with analysis parameters
-
vara_stats is a structure with the following fields (fields names ending with _shuff will be omitted if nshuffs=0; rmsd=root-mean-squared deviation):
-
groupings (struct): grouping information
- ngps (int): number of groups
- gps (int 1-D array): gps(k) is the group assignment of record k, an integer from 1 to ngps
- gp_list (cell array): gp_list{igp} are the indices of the records in group igp
- nsets_gp (int 1-D array): nsets_gp(igp) is the number of records in group igp
- nsets_gp_max (int): maximum size of a group
- tags (int 1-D array): tags(k) is the tag for record k
-
nshuffs (int): number of shuffles used
- shuffs (int 2-D array): shuffles used; shuffs(ishuff,k) is the record used in place of original record k on shuffle ishuff
- opts_multi_used (struct): options used for generating shuffles, see
multi_shuff_groupsfor details - rmsdev_setwise (float 2-D array): rmsdev_setwise(ip,irec) is the rmsd of coordinates in record irec from the global consensus based on data_in.ds{:}{ip}, across all stimuli
- rmsdev_stmwise (float 2-D array): rmsdev_stmwise(ip,istm) is the rmsd of coordinates for stimulus istm from the global consensus based on data_in.ds{:}{ip}, across all records
- rmsdev_overall (float 2-D array): rmsdev_overall(ip,1) is the rmsd of coordinates from the global consensus based on data_in.ds{:}{ip}, across all records and stimuli
- rmsdev_setwise_gp (float 3-D array): rmsdev_setwise_gp(ip,irec,igp) is the rmsd of coordinates in group igp in record irec from its within-group consensus, based on data_in.ds{:}{ip}, across all stimuli
- rmsdev_stmwise_gp (float 3-D array): rmsdev_stmwise_gp(ip,istm,igp) is the rmsd of coordinates in group igp for stimulus istm from its within-group consensus, based on data_in.ds{:}{ip}, across all records
- rmsdev_overall_gp (float 3-D array): rmsdev_overall_gp(ip,1,igp) is the rmsd of coordinates in group igp from the within-group consensus, based on data_in.ds{:}{ip}, across all records and stimuli
- rmsdev_grpwise (float 3-D array): rmsdev_grpwise(ip,1,1) is the rmsd of coordinates from the within-group consensus, across all records and stimuli, averaged over all groups
-
-
The counts for each of these calculations are counts_[overall|setwise|stmwise] and counts_gp_[overall|setwise|stmwise], with first array coordinate fixed at 1 (since dimension does not matter)
- The available rmsd (from zero) is given by rmsavail_[overall|setwise|stmwise].
- If aux_out.vara_stats.nshuffs>0, then a parallel computation is done after random shuffles of the stimulus labels within each record, and the results are returned in rmsdev_[overall|setwise|stimwise]_gp_shuff and rmsdev_grpwise_shuff. For the shuffled quantities, the first three dimensions are the same as for the unshuffled quantities; and dimension 4 (length: nshuffs) is which shuffle. The latter is the key quantity: rmsdev_grpwise_shuff(:,1,1,ishuff), to be compared with the unshuffled values, rmsdev_grpwise, indicates whether the data are more clusted into groups than would be expected by chance.
- To control whether the same random number seed is used on each run, use aux.opts_vara.if_frozen (default is 1).
-
if aux.opts_vara.if_plot=1 (default if if_stats=1), then a figure is created, with three panels:
- a heatmap of rmsdev_setwise as a function of dimension
- a heatmap of rmsdev_setwise_gp as a function of dimension
- a comparison of the rmsd from the group consensus (rmsdev_grpwise, black), overall available rmsd (blue), and quantiles (rmsdev_grpwise_shuff, red) of the rmsd from the group consensus in the shuffled data (quantiles are specified by shuff_quantiles; if nshuffs=0, shuffled values will not be plotted)
Note regarding Procrustes consensus algorithm
- To find a consensus set of coordinates, the coordinates in each record of
data_inare rotated, and optionally translated (if allow_offset=1), scaled (if allow_scale=1), and reflected (if allow_reflection=1). These transformations are carried out for separately for each set dimension for which coordinates are present in all of the records, i.e., for which data_in.ds{k}{idim} exists for all k. - The algorithm, in procrustes_consensus.m, is iterative. Briefly, after an initial guess is determined, a Procrustes transformation is found that minimizes the rms deviation between each record and the current guess. The guess is then revised by setting each stimulus' coordinates equal to the centroid of the coordinates of that stimulus across the records. To avoid drift of the updated guess, it is Procrustes-transformed for closest match to an alignment coordinate set (the alignment set, unless otherwise specified, is equal to the initial guess).
- The iteration ends when either the number of iterations exceeds max_niters (default=1000), or the rms change of the guess is less than max_rmstol (default=10^-5)
-
There are several choices for initialization and alignment.
- For most purposes, the default initialization method (pcon_init_method=0) can be used, which uses the principal components of all the stimulus coordinates in all of the records. These can be optionally forced to be centered (pcon_init_method=-1) or not (pcon_init_method=-2); if unspecified (default), centering is determined by allow_offset. For these choices, if_initpca_rot=1 rotates the initial guess to match the data, or not. The default for if_initpca_rot is 1 unless any of dim_list_out>dim_list_in, in which case it is 0. The heuristic for not rotating if dim_list_out>dim_list_in, i.e., two or more sets of coordinates are to be knit together to construct a coordinate set with a greater number of dimensions, is that without rotation, the principal components reflect projections of the coordinates that are present in any of the records.
- Alternatively, pcon_init_method=r, r>0, specifies that the coordinates in data_in{r}{idim} are used.
- If pcon_init_method='specify', then pcon_initial_guess{idim} is an array of size [npts ids] for the initial guess, and pcon_alignment{idim}, which defaults to pcon_initial_guess, is used for the alignment at the end of each iteration. pcon_initial_guess and pcon_alignment may be omitted, in which case random values are used. To control whether the same random number seed is used on each run, use if_frozen (default is 1, which uses the same random numbers on each run).
- The solution is only unique up to rotation (and translation and reflection, if these components are allowed). The ambiguity is resolved by matching the consensus solution to the initial guess (or, pcon_alignment{idim} if separately supplied with pcon_init_method=0), as described above.
-
Under some circumstances (e.g., several solutions that are nearly equally good), the solution found by the algorithm may depend on the initialization choice. A simple strategy to check for this is to compare the results with the default pcon_init_method=0 to the results with pcon_init_method='specify' and if_frozen=0. There are two ways that this dependency can happen.
- One is that the number of overlapping stimuli is too small. For example, at least m points are required to determine a rotation and translation in an m-dimensional space; if there are fewer overlaps, then a consensus will still be found but there are many other consensus datasets that fit equally well.
- A second way is that there are a sufficient number of points, but there are several solutions that are approximately equally good.
Under these circumstances, the algorithm may get stuck in a local minimum. This possibility only occurs when there are at least three records in
data_in, as the procedure reduces to the standard Procrustes algorithm, which finds the consensus when there are only two records, is deterministic other than does rotational ambiguity.
Note regarding replotting a previous analysis
-
To replot a previous calculation with additional customization or to make a composite figure, proceed as follows:
data_inandgroupingsshould be equal to that used in the previous calculation.- aux.vara_stats should be equal to vara_stats from the previous calculation
- aux.vara_stats_setup should be equal to aux_out.vara_stats_setup from the previous calculation
-
The following modifications are allowed in fields of vara_stats_setup:
- dataset_labels (cell array of char): dataset labels; default is data_in.sets{:}.label
- stimulus_labels (cell array of char): stimulus labbels; default is data_out.sas{1}.typenames
- shuff_quantiles (float 1-d array): quantiles to show; default is 0.01 0.05 0.5 0.95 0.99
- fig_handle (handle): figure handle to plot into; figure will be created if not supplied
- row (int): row to plot into; default is 1
- nrows (int): number of rows in the figure; default is row
-
No further calculations are done
- On return, vara_stats will be empty and aux_out.fig_handle will be the figure handle
- In creating a composite figure, rows should be plotted in order from top to bottom, as plotting the bottom row triggers an equalization of the color scale.
Source code in src/rs_vara_coordsets.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 | |
rs_warning(msg, if_bad, opts_warn)
opts_used=rs_warning(msg,if_bad,opts_warn) displays a warning message and updates a structure of warning tallies and messages
Input arguments:
-
msg(char or vertical concatenation of char) –one or more warning messages
-
if_bad(int) –severity, can =be omitted; 1 indicates that furhter processing cannot proceed, 0 is less serious; default is 1
-
opts_warn(struct) –options, can be omitted, with fields
if_warn(int) – 1 to display warning, 0 to omit; default is 1warnings(char or vertical concatenaton of char) – previous warnings; default is []warn_bad(int) – current tally of serious warnings; default is 0- warn_leadin (char) a prefix for warnings echoed at console;
default is '##### rs_warning: '; can be modified by editing
rs_aux_defaults_define if_warn_traceback(int) – 1 to show a traceback with each warning, 0 to omit; default is 0; if 1, forces if_warn to 1
Output arguments:
-
opts_used(struct) –updated opts_warn structure
Typical usage
Typical usage is aux_out=rs_warning(wmsg,1,setfield(aux_out,'if_warn',aux_out.if_warn)) [?how to show code?] which appends the warning message 'wmsg' to aux_out.warnings, and increments tally of aux_out.warn_bad
Source code in src/rs_warning.m
rs_write_coorddata(fullname, data_in, aux)
aux_out=rs_write_coorddata(fullname,data_in,aux) writes a single record in a dataset structure to a file
Input arguments:
-
fullname(char or singleton cell array) –file name with path, if empty, it will be requested interactively. The file name should contain the string '_coords'
-
data_in(struct) –dataset structurecontaining the record to be writtends(cell array) –coordinate structure, ds{k}{idim} is an array of [nstims idim] of coordinates for the kth recordsas(cell array) –stimulus metadata structure, sas{k} is the stimulus metadata for the kth recordsets(cell array) –set metadata structure, sets{k} is the response metadata for the kth record
-
aux(struct) –auxiliary options, with fields
opts_write(struct) – , with fieldsset_no(int) – record number to write; default is 1if_embed(int) – 1 to embed thesetup metadatain the output file, 0 to omit; see note below re setup metadata; default is 1.ui_prompt(char) – User interface prompt, default ia ,'Select a coordinate file to write'if_gui(int) – 1 to use graphical interface to get files if file names are not supplied; 0 to use text prompt; default is 0if_log(int) – 1 to log progress, 0 to omit; default is 1data_fullname_def(char) – default file name to write, used as a prompt if if_gui=0 if fullname is not provided; default is '[path and file name for the default coordinate dataset file to write].mat'; default can be changed by editing the line containing generic.opts_write.coord_data_fullname_write_def inrs_aux_defaults_define, running it once, and saving the workspace as rs_aux_defaults.mat.if_uselocal(int) – should be set to 0 (default); 1 (intended for maintenance only) overrides options set byrs_aux_defaults_defineby defaults inpsg_localopts.m
Output arguments:
-
aux_out(struct) –
Note: Note re setup metadata
- The
setup metadatais required forbinary texture domaindatasets; not otherwise required unless configured on installation. - If
setup metadatais required, it is read along with the coordinate data byrs_read_coorddataorrs_get_coordsets, and kept in data_in{k}.sas; it is also updated byrs_align_coordsetsandrs_knit_coordsets - if_embed=1 embeds the metadata in the written file, so that the setup file no longer needs to be read.
See also: rs_aux_customize.
Source code in src/rs_write_coorddata.m
rs_xform_apply(data_in, xforms, aux)
[data_out,aux_out]=rs_xform_apply(data_in,xforms,aux)
applies a transformation structure to the coordinates in a dataset structure
A transformation structure is a cell array of geometric transformations.
This module can apply several types of transformations: linear, linear with offset (affine), projective, piecewise affine, and piecewise projective.
Input arguments:
-
data_in(struct) –dataset structureto be aligned containing n records, with fieldsds(cell array) –coordinate structure, ds{k}{idim} is an array of [nstims idim] of coordinates for the kth recordsas(cell array) –stimulus metadata structure, sas{k} is the stimulus metadata for the kth recordsets(cell array) –set metadata structure, sets{k} is the response metadata for the kth record
-
xforms(struct) –specification of the transformations, typically an output structure from
rs_xform_specifyts(cell array) – ts{k}{idim} is the transformation to be applied to the coordinates of dimension idim in record k; see note below regarding transformationspipeline(struct) – a structure that becomes the starting point for the 'pipeline' field of aset metadata structurewhen the transformations are applied, may be omitted; default is omitted
-
aux(struct) –auxiliary options, may be omitted, with fields
opts_xform(struct) – specification of the transformation, with fieldsclass(char) – 'affine','mean','procrustes','projective','pwaffine','pwprojective'; default is 'affine'; seetransformation structuresand note below regarding transformationsif_warn(int) – 1 (default) to show warnings
opts_check(struct) – options for consistency checking, with fieldif_warn(int) – 1 to show warnings when datasets are checked for consistency, 0 to suppress; default is 1
Output arguments:
-
data_out(struct) –a
dataset structurewith the transformations applied, same format as asdata_in -
aux_out(struct) –auxiliary outputs and parameter values used, with fields
Note regarding transformations
-
xforms.ts{k}{idim} is the transformation to be applied to record k in
data_in, i.e., to the coordinates data_in.ds{k}{idim}.- If length(xforms.ts{k})<length(data_in), transformations are used in cyclic order.
- If any of xforms.ts{k}{idim} are missing, then the coordinates in data_in.ds{k}{idim} are passed to
data_outunchanged.
-
Several classes of transformations, specified by aux.opts_xforms.class, are supported (see
transformation structures). The parameters in xforms.ts{k}{idim} have the following meaning, where output and input both have size [nstims idim], and ts=ts{k}{idim}:- affine: [output(istim,:)]=ts.b * [input(istim,:)] * ts.T + ts.c;
where size(b)=1, size(T)=[idim,idim], and size(c)=[1 idim]. If these fields are not present and xform.class='affine', then
alternative parameter names are allowed: 'scaling' for b, 'orthog' for T, and 'translation' for c.
This allows for compatibility with the transformations produced by
procrustes_consensus. - procrustes: same as affine, but ts.b=1 and abs(det(T))=1. These are not checked.
- mean: same as affine, but ts.b=1, T=0. These are not checked.
- projective: affine parameters and also p, size [isim 1]. p=0
reduces to affine. See
transformation structuresfor further details. - pwaffine (piecewise affine): b as in affine. T has size [idim idim 2^ncuts] and c
has size [2^ncuts idim], specifying the affine transformation on
each cut. vcut has size [ncuts idim], each row is a unit vector,
orthogonal to the cutplanes. acut has size [1 2^ncuts], specifying the cutpoints.
See
transformation structuresfor further details. - pwprojective (piecewise projective): parameters as in pwaffine, and also p, of size [idim, 2^ncuts], used as in projective for each component
See
transformation structuresfor further details.
- affine: [output(istim,:)]=ts.b * [input(istim,:)] * ts.T + ts.c;
where size(b)=1, size(T)=[idim,idim], and size(c)=[1 idim]. If these fields are not present and xform.class='affine', then
alternative parameter names are allowed: 'scaling' for b, 'orthog' for T, and 'translation' for c.
This allows for compatibility with the transformations produced by
See also: rs_aux_customize, rs_check_coordsets, rs_xform_specify, RS_FORM_SPECIFY_APPLY_TEST, PSG_GEOMODELS_APPLY, procrustes_compat.
Source code in src/rs_xform_apply.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
rs_xform_specify(data_in, aux)
[xforms,aux_out]=rs_xform_specify(data_in,aux)
creates a transformation structure in the affine model class based the coordinates in a dataset structure
A transformation structure is a cell array of geometric transformations.
The transformation structures created by this module are combinations of linear transformations and translations.
These transformations can be chosen to center the coordinates in data_in
(i.e., move the centroid to the origin), to move the coordinates of a
specific stimulus to the origin, and/or or rotate the coordinates into their principal components.
To fit a geometric model to a transformation between coordinate sets, see rs_geofit
Input arguments:
-
data_in(struct) –dataset structureto use for specifying the transformations, with fieldsds(cell array) –coordinate structure, ds{k}{idim} is an array of [nstims idim] of coordinates for the kth recordsas(cell array) –stimulus metadata structure, sas{k} is the stimulus metadata for the kth recordsets(cell array) –set metadata structure, sets{k} is the response metadata for the kth record
-
aux(struct) –auxiliary options, may be omitted, with fields
opts_xform(struct) – specification of the transformation, with fieldsmode(char) – One of 'none', 'translate','offset_pca','translate_then_pca'; default is 'none'- 'none': the identity transformation
- 'translate': a point specified by 'centering_specifier' (see below) is translated to the origin
- 'offset_pca': the data are rotated into the principal components around the point specified by 'centering_specifier' (see below). The first coordinate explains the most variance around that point, the second coordinate explains the next-most-variance, etc. The point specified by the 'centering_specifier' is not moved.
- 'translate_then_pca': the point specified by 'centering_specifier') is translated to the origin, and then standard pca is done.
source(char) – 'global','local', or an integer in [1:n], where n is the number of records, equal to length(data_in.ds); default is 'global'- 'global' (default): the centering specifier is determined from the mean across records; pca is computed across all records; the transformations specified for all records are identical
- 'local': the centering specifier and pca is computed separately for each record; tranformations for each record typically differ
- an integer: the specified record is used for the centering specifier and pca; transformations foe all records are identical
centering_specifier(char) – 'none','centroid','index','typename','value'; default is 'none'- 'none': no centering is done
- 'centroid': centroid is the centering point
- 'typename': use the stimulus corresponding to aux.opts_xform.centering_typename in data_in.sas{k}.typenames for centering
- 'index': use the value in aux.opts_xform.centering_index, as the index number of the stimulus whose coordinates are to be used for centering. Caution: the index refers to the position of the stimulus in data_in.ds{k}, and stimulus order may differ across datasets. To avoid mis-referencing stimuli, specify by typename.
- 'value': use the coordinates in aux.opts_xform.,centering_value for centering
centering_typename(char) – the label of the stimulus in data_in.sas{k} to be used for centeringcentering_index(int) – the index in data_in.ds{k} to be used for centeringcentering_value(float 1-D array) – the coordinates to be used for centering; for coordinate sets of dimension k, only the first k are used aux.opts_xform.centering_[index|typename|value]: see above in aux.opts_xform.centering_specifierif_warn(int) – 1 (default) to show warnings
opts_check(struct) – options for consistency checking, with fieldif_warn(int) – 1 to show warnings when datasets are checked for consistency, 0 to suppress; default is 1
Output arguments:
-
xforms(struct) –the transformations, with fields
ts(cell array) – ts{k}{idim} is the transformation to be applied to the coordinates of dimension idim in record k. See note below regarding transformationsclass(string) – model class of the transformation; this is always 'affine'. Seetransformation structurespipeline(structure) – a structure that indicates how the transformation is specified, and can serve as the 'pipeline' field of aset metadata structurewhen the transformations are applied
-
aux_out(struct) –auxiliary outputs and parameter values used, with fields
Note regarding transformations
- The transformations specified by
rs_xform_specifyare combinations of translations and linear transformations, and belong to the model class 'affinedescribed intransformation structures`. With ts=xforms.ts{k}{idim}, and each input a row vector, the transformation is [output]=ts.b[input]ts.T+ts.c, where ts.b is a scalar, ts.T is an array of size [idim,idim], [input] is an array of size [nstims,idim], and c is a row vector of length idim. - This structure is identical to the output of Matlab's procrustes.m, [??how to hyperlink], except that the translation ts.c in procrustes.m is an array of identical rows; here it is just one row.
- This structure is also identical to that of
aux_out.knit_stats.ts{idim}{k}, where the roles of ts.b, ts.T, and ts.c are
replaced by ts.scaling, ts.orthog, and ts.translation.
ts_specify{k}{idim}=procrustes_compat(ts_knit{idim}{k}) can be used
to convert the transformations produced by
ts_knit_coordsetsto the transformations produced byrs_xform_specify.
See also: rs_aux_customize, rs_check_coordsets, PSG_PCAOFFSET, rs_xform_specify_test, rs_xform_apply.
Source code in src/rs_xform_specify.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
rs_aux_defaults_define_dist
rs_aux_defaults_define sets the defaults for auxiliary input parameters.
Run this file in a clean workspace, and save the resulting workspace in rs_aux_defaults.mat.
The resulting file rs_aux_defaults.mat is read by rs_aux_customize at run-time, to set defaults for auxiliary input parameters.
This file, rs_aux_defaults_define.m (or rs_aux_defaults_define_dist.m), is intended for distribution and customization. If inadvertently over-written, a spare copy is in rs_aux_defaults_define_dist.m, and the mat-file it creates is saved in rs_aux_defaults_dist.mat.
Search for '[' to find typical fields to be customized.
rs_aux_defaults_define
rs_aux_defaults_define sets the defaults for auxiliary input parameters.
Run this file in a clean workspace, and save the resulting workspace in rs_aux_defaults.mat.
The resulting file rs_aux_defaults.mat is read by rs_aux_customize at run-time, to set defaults for auxiliary input parameters.
This file, rs_aux_defaults_define.m (or rs_aux_defaults_define_dist.m), is intended for distribution and customization. If inadvertently over-written, a spare copy is in rs_aux_defaults_define_dist.m, and the mat-file it creates is saved in rs_aux_defaults_dist.mat.
Search for '[' to find typical fields to be customized.
rs_aux_defaults_define_pvt
rs_aux_defaults_define_pvt sets the defaults for auxiliary input parameters.
This version of the file is intended for local use in the Victor lab and is provided as an example of customization; see rs_aux_defaults_define for distribution version.
Run this file in a clean workspace, choose whether to take the for binary texture data or calcium imaging data, and, if these defaults are to be used, save the resulting workspace in rs_aux_defaults.mat.
The resulting file rs_aux_defaults.mat is read by rs_aux_customize at run-time, to set defaults for auxiliary input parameters.
Results of choosing the binary texture option are saved in rs_aux_defaults_btc.mat. Results of choosing the calcium imaging option are saved in rs_aux-defaults_hlid.mat.
/src/utils
compare_signflip(x, y, dimflip)
[ifdif,maxdiff,maxdiff_noflip,diffs,diffs_noflip,signs]=compare_signflip(x,y,dimflip) compares two numeric arrays, allowing for sign flips
This is a utility used to verify computations against benchmarks, recognizing that PCA implementations may differ in sign assignemnts.
Input arguments:
-
x(array or cell array) –one array to be compared
-
y(array or cell array) –second array to be compared
-
dimflip(int) –dimension that can be flipped, defaults to 1
Output arguments:
-
ifdif(char) –empty if x and y are identical or identical after sign flips along dimension dimflip; otherwise, 'different types', 'different shapes' or 'different values', depending on first difference encountered
-
maxdiff(float) –maximum absolute value of difference between x and y, after sign flips along dimflip to minimize differences
-
maxdiff_noflip(float) –maximum absolute value of difference between x and y, without sign flips
-
diffs(float array) –maximum absolute value of difference between x and y along the dimension dimflip, after sign flips to minimize differences
-
diffs_noflip(float array) –maximum absolute value of difference between x and y along the dimension dimflip, without sign flips
-
signs(int) –+1 or -1, indicating whether the difference between x and y is minimized by a flip; 0 if x and y are both 0
Array outputs
The arrays diffs, diffs_noflip, and signs are empty if x and y differ in type or shape, and therefore cannort be compared numerically.
If x and y can be compared numerically, the arrays diffs, diffs_noflip, and signs all have same shape as x and y except on the dimension dimflip, where they have length 1
Source code in src/utils/compare_signflip.m
compstruct(parent1, x1, parent2, x2, varargin)
ifdif=compstruct(parent1,x1,parent2,x2,varargin) compares two structures
This function is adapted from a file "compare.m" downloaded from the MATLAB file exchange on 6/4/04, from Nicholas Gigis, gigisn@netscape.net. Original documentation is retained at the beginning of the code.
Input arguments:
-
parent1(char) –name of first structure to be compared
-
x1(struct) –first structure to be compared
-
parent2(char) –name of second structure to be compared
-
x2(struct) –second structure to be compared
Output arguments:
-
ifdif(char) –text string of differences, empty if structures are identical
Source code in src/utils/compstruct.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
extorthb(cv)
[basis,onb]=extorthb(cv) extends a column vector to an orthogonal basis
The extension is attempted in a numerically "good" way, not by simply doing a Gram-Schmidt procedure
Input arguments:
-
cv(float 1-D array) –a column vector
Output arguments:
-
basis(float 2-D array) –a square matrix, size(basis)=[length(cv) length(cv)]; basis(:,1)=cv, basis'*basis is diagonal
-
onb(float 2-D array) –corresonding orthonormal basis, vectors in columns; onb'*onb=1
See also: grmscmdt, extorthb_gen.
Source code in src/utils/extorthb.m
extorthb_gen(v)
[basis,onb]=extorthb_gen(v) extends a set of column vectors to an orthogonal basis
The extension is attempted in a numerically "good" way, not by simply doing a Gram-Schmidt procedure
Input arguments:
-
v(float 2-D array) –a set of column vectors, assumed to be orthonormal.
Output arguments:
-
basis(float 2-D array) –basis a square matrix, size(basis)=[size(v,1) size(v,1)], basis'basis and basisbasis' is the identity
- If v is orthonormal, then basis(:,1:size(v,2))=v
- If v is not orthonormal, then v is in the span of the first size(v,2) columns of basis, with v(:,1) proportional to basis(:,1), v(:,k) in the span of basis(:,1:k). Coefficients are in in basis'*v, which is upper-triangular
-
onb(float 2-D array) –same as basis, for backwards compatibility
Source code in src/utils/extorthb_gen.m
fibspiral(n, d, opts)
x=fibspiral(n,d) produces a sampling of points on the surface of a d-dimensional hypersphere
The method is inspired by this Math Stack Exchange post
Input arguments:
-
n(int) –number of points
-
d(int) –dimension. Should work for any number of dimensions >=1
- d=1 yields samples that alternate between +1 and -1
- d=2 yields smaples equally spaced around a circle
- d>=3 yeilds nontrivial spirals
-
opts(struct) –options structure, with fields
nangs_min(int) – minimal sampling for the axial angle; default is 1024nangs_mult(int) – minimal factor for the number of points in sampling the axial angle; default is 16mults(float 1-D array) – list of incommensurate numbes of length at least d-1; if shorter or not provided, square roots of lowest primes are used
Output arguments:
-
x(int) –array of size[n d] of the sampled points, magnitude 1
-
opts_used(struct) –options used
See also: filldefault, hsphere_sample.
Source code in src/utils/fibspiral.m
filldefault(opts, names, val)
optsused=filldefault(opts,names,val) fills an option structure with default values
Input arguments:
-
opts(struct) –an option structure, possibly with some fields missing
-
names(char or char 2-D array) –field name or names to be supplied with default values
-
val(int, float, char, cell, or struct) –the value to use as default, for each field in 'names' that is not present in 'opts'
Output arguments:
-
optsused(struct) –opts, with missing fields filled in
Source code in src/utils/filldefault.m
getinp(prompt, type, limits, default)
vals=getinp(prompt,type,limits,default) gets an input value or values from the console and supplies a default
Input arguments:
-
prompt(char) –a prompt string, to appear after "Enter"
-
type(char) –'d','f','s' for integer, float, or string input; input value is required to be an integer if 'd' is used
-
limits(int 1-D array or float 1-D arrray) –limits(1) and limits(2) are low and high limits for input; ignored and may be empty if 'type'='s'
-
default(int 1-D array or float 1-D array) –default value(s) used if console response is empty
Output arguments:
-
vals(int 1-D array, float 1-D array, or char) –value(s) entered at console, or default if no value is entered
Source code in src/utils/getinp.m
getsubfield(s, fns)
x=getsubfield(s,fns) gets a (possibly deeply) nested subfield
Input arguments:
-
s(struct) –a structure
-
fns(cell array) –field names, fns={n1, n2,..., nk}
Output arguments:
-
x(int, float, cell, or struct) –the nested subfield s.(n1).(n2). ... .(nk)
Notes
If any of the subfields are not present, x=[].
Subfield arrays not supported.
Uses recursion:
- k>=2: getsubfield(s,{n1, n2,..., nk})=getsubfield(s.(n1),{n2,..., nk})
- k=1: getsubfield(s,{n1})=s.(n1)
See also: rmsubfield.
Source code in src/utils/getsubfield.m
grmscmdt(a)
[gs,gsn]=grmscmdt(a) applies the Gram-Schmidt procedure to a set of column vectors
Input arguments:
-
a(float 2-D array) –a set of column vectors
Output arguments:
-
gs(float 2-D array) –orthogonal column vectors; span of first k columns match those of a
-
gsn(float 2-D array) –orthonormal column vectors; span of first k columns match those of a
Notes
If some columns of a are linearly dependent, then gs and gsn will have some columns that are zero.
This works if a is complex. gs'*gs will be diagonal, and gsn'*gsn will be the identity.
See also: extorthb, extorthb_gen.
Source code in src/utils/grmscmdt.m
hsphere_sample(d, opts)
[pts,opts_used]=hsphere_sample(d,opts) samples the surface of a hypersphere with a requested number of points
Input arguments:
-
d(int) –number of dimensions (2=circle, 3=ordinary sphere)
-
opts(struct) –options structure, with fields
if_hemisphere(int) – 0 to sample whole hypersphere, 1 to sample only the hemi-hypersphere in which first coordinate is >0; default is 0method(char) – sampling method to use, with the following options; default is 'random'- 'axes': one point on each axis, yields 2*d/(1+opts.if_hemisphere) points
- 'orthants': one point in each orthant, yields 2d/(1+opts.if_hemisphere) points
- 'axes_and_orthants': one point on each axis and in each orthant, combines 'axes' and 'orthants'
- 'random': random
- 'fibspiral': Fibonacci spiral
nsamps(int) – number of points to sample, ignored if method='random' or 'fibspiral'; default is 2d for 'random' and 4d for 'fibspiral'
Output arguments:
-
pts(float 2-D array) –array of size [nsamps d]; each row is a unit-length point on the hypersphere
-
opts_used(struct) –options used
See also: filldefault, int2nary, fibspiral.
Source code in src/utils/hsphere_sample.m
int2nary(ints, d, pmin)
nary=int2nary(ints,d,pmin) converts one or more integers to n-ary vectors
The resulting vectors run along the first unused dimesion of ints, as integers base d. The least significant bit is in position 1, and zero-padding is used if needed. Generalized n-ary conversion is also done.
Input arguments:
-
ints(int or int array) –the integers
-
d(int or int array) –the base, default is 2 if omitted or empty. d may be a vector; see note below regarding generalized n-ary conversion
-
pmin(int) –minimum length of the created dimension; if omitted, minimum possible value is used
Output arguments:
-
nary(int array) –the converted array of n-ary numbers
Generalized n-ary conversion
If d is a vector, then d(1) is used for the first place, d(2) for the second, etc. and d(end) used if d does not have sufficient length.
In this case, ints(k)=nary(k,1)+d(1)*nary(k,2)+d(1)*d(2)*nary(k,3)+...
This reduces to the usual n-ary representation if d is a scalar
See also: nary2int.
Source code in src/utils/int2nary.m
isgraphc(connect, if_fast)
[isgraph,msg,niters]=isgraphc(connect,if_fast) determines whether a matrix is consistent with a connected graph
This works for directed graphs, and can also be used to compute a graph's diameter.
Input arguments:
-
connect(int 2-D array) –a square connectivity matrix: connect(i,j)=1 if there is a connection from node i to node j. For directed graphs, the matrix will not be symmetric.
-
if_fast(int) –algorithm choice, default is 0
- 0: use sparse matrix methods rather than squaring; on return, niters+1 is the graph diameter
- 1: use successive squaring; on return, niters+1 is not necessarily the graph diameter
Output arguments:
-
isgraph(int) –1 if graph is connected and symmetric, -1 if connected but directed, 0 if not connected or not a graph
-
msg(int) –reason for isgraph~=1
-
niters(int) –number of iterations used
See also: procrustes_consensus.
Source code in src/utils/isgraphc.m
loglik_beta_discrete(ab, obs, opts)
[loglik,opts_used]=loglik_beta_discrete(ab,obs,opts) determines the log likelihood (natural log) for a beta distribution (Dirichlet prior) with discrete part, based on a set of observations
Input arguments:
-
ab(int 1-D array) –Dirichlet parameters a=ab(1), b=ab(2), or a=b=ab(1) if scalar; a and b must be >0
-
obs(int 2-D array) –a vector of observations where obs(:,1) is successes and obs(:,2) is total tries
-
opts(struct) –options, with fields
hvec(float 1-D array) – vector of weights for point-mass probabilities, must be all >=0 and sum to <=1 (not checked for), defaults to [];qvec(float 1-D array) – vector of probabilities corresponding to the elements of hvec, must all be strictly >0 and < 1
Output arguments:
See also: LOGLIK_BETA, BETALN, filldefault.
Source code in src/utils/loglik_beta_discrete.m
mindex_inv(dimranges, indexes)
[vecs,mults,addoff]=mindex_inv(dimranges,indexes) implements a multi-indexing scheme with ranges are in dimranges
This allows for arbitrary start and stop indices along each dimension. In contrast to mindex_make, the first entry in dimranges is the outer loop, i.e., cycles the slowest.
Input arguments:
-
dimranges(int 2-D array) –an array of size [ndims 2], dimranges(k,1) is the lowest index (typically 0 or 1), dimranges(k,2) is the highest index for dimension k
-
indexes(int 1-D array) –a column vector of scalars to convert to a multi-index; if not supplied, then the max of each row of dimranges is assumed
Output arguments:
-
vecs(int 2-D array) –array of size [length(indexes),ndims]: vecs(k,b) is the multi-index converted from indexes(b); each vecs(k,b) is in [dimranges(k,1) dimranges(k,2)]
-
mults(int 1-D array) –a column of length ndims
-
addoff(int) –offset to convert from vecs to indices, if supplied; indices=vecs*mults+addoff
See also: mindex_make.
Source code in src/utils/mindex_inv.m
mindex_make(dims)
[mindex,mults]=mindex_make(dims) creates a multi-indexing scheme for an array whose dimensions are in dims
Input arguments:
-
dims(int 1-D array) –length of each dimension
Output arguments:
-
mindex(int 2-D array) –array of size [prod(dims) length(dims)], in which mindex(:,id) has values from 0 to dims(id)-1, mindex(:,1) cycles most rapidly, and all rows are unique
-
mults(int 1-D array) –a column of length length(dims), containing [1 dims(1) dims(1)*dims(2) ... dims(1)*...*dims(end-1)]. mindex*mults is [0:prod(dims)-1]
See also: mindex_inv, mindex_make_check.
Source code in src/utils/mindex_make.m
mindex_make_check(tags, opts)
[opts_used,mindex,mults]=mindex_make_check(tags,opts) creates or checks a multi-index computed by mindex_make
Input arguments:
-
tags(int or float array) –target for multi-indexing: a multidimensional array (typically of integers), must have dimension >=2
-
opts(struct) –options, with fields
mindex(int 2-D array) – multi-index array, frommindex_make, computed if not suppliedmults(int 1-D array) – multiplier frommindex_make(computed if not supplied)
Output arguments:
-
opts_used(struct) –opts, with mindex, mults computed
-
mindex(int 2-D array) –opts_used.mindex
-
mults(int 1-D array) –opts_used.mults
See also: mindex_make, filldefault
Source code in src/utils/mindex_make_check.m
multi_shuff_enum(counts, opts)
[a,opts_used]=multi_shuff_enum(counts,opts) enumnerates all the ways of ordering counts(1) 1's, counts(2) 2's, etc.
The algorithm is recursive.
Input arguments:
-
counts(int 1-D array) –how many 1's, 2's, 3's, etc. Only non-negative integer entries
-
opts(struct) –
Output arguments:
-
a(int 2-D array) –a list of the shuffles, each row contains counts(1) 1's, counts(2) 2's, etc
-
opts_used(struct) –options used
Multiplicities
The number of rows in a, dim(a,1) is sum(counts)!/prod(counts(k)!)/r, a multinomial coefficient possibly divided by r, if if_reduce=1, where r is a product of the factorials of the multiplicities of the counts. For example, with counts=[2 3 3 2 2 2], there are 4 tokens that appear twice (1,4,5, and 6), and 2 tokens that appear three times (2 and 3), so r=4!*2!
counts=[2 3 3 2 2 2];
tic;[q,ou]=multi_shuff_enum(counts,setfields(struct(),{'if_log','if_reduce'},{0 1}));toc
Elapsed time is 4.552206 seconds.
disp(size(q))
3153150 14
disp(factorial(sum(counts))/prod(factorial(counts))/24/2)
3153150
disp(q([1:500000:size(q,1)],:))
1 1 2 2 2 3 3 3 4 4 5 5 6 6
2 1 2 4 3 5 1 3 2 5 6 3 4 6
2 2 3 1 4 5 3 4 3 6 1 5 6 2
1 4 2 3 1 4 2 5 6 2 3 6 3 5
2 1 4 2 4 5 2 6 5 3 3 6 1 3
1 4 5 2 3 3 6 4 2 2 6 1 3 5
1 4 5 2 6 2 1 5 4 3 3 6 2 3
See also: NCHOOSEK.
Source code in src/utils/multi_shuff_enum.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
multi_shuff_groups(gps, opts)
[shuffs,gp_info,opts_used]=multi_shuff_groups(gps,opts) creates lists of shuffles between groups, that optionally:
Optionally, the shuffles can be forced to preserve an auxiliary tag (so that only elements with the same tag are exchanged).
Optionally, the list of shuffles can be exhaustive.
Optionally, if exhaustive, the list of shuffles can be reduced by symmetry so that shuffles that differ only by the order of the groups are not considered different.
The algorithmn for auxiliary tags relies on recursion, but recursion only one step deep.
Input arguments:
-
gps(int 1-D array) –a row vector of length n, that indicates the assignment of each element to [1:ngps]. Not all of [1:ngps] must be present.
-
opts(struct) –structure, may be omitted, with fields
if_log(int) – 1 to log; default is 0if_ask(int) – 1 to ask if_reduce, if_exhaust, nshuffs, -1: ask only about if_exhaust and nshuffs; default is 0if_exhaust(int) – 1 to attempt to do exhaustive list, 0 for random shuffles; defaults is 0if_reduce(int) – 1 to reduce by symmetrizing, defaults is 0; ignored if if_exhaust=0if_justcount(int) – 1 to count number of shuffles but not compute them; 0 also computes; defaults is 0if_nowarn(int) – 1 to suppress warnings; defaults is 0if_sortrows(int) – 1 to sort shuffle list by rows; default is 0nshuffs(int) – number of shuffles if random shuffles are used, default is 1000exhaust_raw_max(int) – maximum number of shuffles if exhaustive list is requested, before reduction by symmetry; defaults is 10^9exhaust_reduced_max(int) – maximum number of shuffles if exhaustive list is requeted, after reduction by symmetry; default is 10^6nshuffs_max(int) – maximum number of shuffles if exhaustive list is requete3d, default is min(exhaust_raw_max,exhaust_reduced_max)tags(int 1-D array) – row vector of length n, containing values [1:ntags]; shuffles will only exchange values with the same tags. Ignored if empty or all values equal. Not all of [1:ntags] need be represented. Defaults to ones(1,n)
Output arguments:
-
shuffs(int 2-D array) –the shuffles; each row is a permutation of [1:n]
-
gp_info(struct) –group information, with fields
ngps(int) – number of groupsgps_unique(int 1-D array) – unique group numbers, in ordergp_list(cell array) – gp_list{igp} which elements in each group, with igp a pointer into gps_uniquensets_gp(int 1-D array) – number of datasets in each group, in order of gps_uniqueexhaust_raw(int) – number of shuffles if exhaustive, prior to reduction by symmetryexhaust_reduced(int) – number of shuffles if exhaustive, after reduction by symmetrytags(cell array of struct) – structure with field 'tag' indicating the tag numnber, and field 'gp_info' with gp_info for the tag
-
opts_used(struct) –opts, with defaults filled in
Reduction by symmetry
- If if_reduce=1, then groups of the same size, and that contain the same number of items for each tag, are considered identical and not separatelyh listed.
- That is, for every set of groups that have the same number of items with each tag, the groups are ordered in order of the lowest-occurring element within each group.
- Groups that have the same size but differ in the number of elements that they contain of each tag are considered different. For example, if gps=[1 1 1 2 2 2] and tags=[1 1 2 2 2 1], then items [1 2 6] can be permuted (tag=1), and independently items [3 4 5] can be permuted (tag=2), but even though both groups have 3 elements, the first group is distinguished since it has two elements with a tag of 1. But if gps=[1 1 1 2 2 2] and tags=[1 1 2 1 1 2], then there are 6 rearrangements of items [1 2 4 5], and 2 rearrangements of items [3 6], for a total of 12=6*2 shuffles into two groups of 3. However, with if_reduce=1, these are reduced by a factor of two since the first and second groups both have the same complements of each tag.
See also: NCHOOSEK, multi_shuff_enum.
Source code in src/utils/multi_shuff_groups.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
nary2int(nary, d, lastdim)
ints=nary2int(nary,d,lastdim) converts one or more vectors, considered as integers base d, to integers
One value of ints is calculated for each element in the first ndims(nary)-1 dimensions of nary. The last dimension of nary is the base-d expansion, with the least significant bit in position 1.
Input arguments:
-
nary(int array) –an array of n-ary numbers
-
d(int or int array) –the base, 2 if omitted, d may be a vector; see note below regarding generalized n-ary conversion
-
lastdim(int) –last dimension of nary; default is ndims(nary). Required if, for example, size(nary)=[10 7] but this is thought of as [10 7 1]
Output arguments:
-
ints(int or int array) –the converted integers.
Generalized n-ary conversion
If d is a vector, then d(1) is used for the first place, d(2) for the second, etc. and d(end) used if d does not have sufficient length.
In this case, ints(k)=nary(k,1)+d(1)*nary(k,2)+d(1)*d(2)*nary(k,3)+...
See also: int2nary.
Source code in src/utils/nary2int.m
nicesubp(nsubplots, aspect)
[nr,nc,aused]=nicesubp(nsubplots,aspect) finds a nice number of rows and columns to put nsubplots into a figure
Input arguments:
-
nsubplots(int) –number of subplots to position
-
aspect(float) –desired aspect ratio of overall plot; default is 1
- If a scalar, the height/width ratio
- if [v1,v2], the allowed range
Output arguments:
-
nr(int) –number of rows in subplot array
-
nc(int) –number of columns in subplot array
-
aused(float) –aspect ratio used
Source code in src/utils/nicesubp.m
overlap_heuristics(overlaps)
h=overlap_heuristics(overlaps) computes several heuristics for whether the number of overlaps of pairwise distances across several datasets suffices for a well-defined knitting across these datasets
Input arguments:
-
overlaps(int 2-D array) –overlaps(istim,iset) is 1 if stimulus istim is present in record iset, 0 otherwise
Output arguments:
-
h(struct) –structure of heuristics, with fields
nstims(int) – number of stimuli (size(overlaps,1))nstims_used(int) – number of stimuli present in at least one recordnpairs(int) – total number of pairwise distances within recordsnmax(int) – maximum number of pairwise distances if all stimuli were in the same recordcounts(int 2-D array) – counts(istim,jstim) is the number of records that contain both stimulinfree(int 1-D array) – nfree(iset) is the number of stimuli unique to record isetnbound(int 1-D array) – nbound(iset) is the number of stimuli in record iset that are in at least one other recordnovlp(int 2-D array) – novlp(iset,jset) is the number of stimuili in common between records iset and jsetdmax_free(int) – maximum dimension that is rigidly constrained by bound points, equal to min(nbound-1) for all records with nfree(irec)>0dmax_constraints(int) – maximum dimension for which number of coordinates to be found, minus offset and rotational d.o.f., does not exceed npairsdmax(int) – maximum dimension for which a well-defined knitting solution can be expected, min(dmax_free,dmax_constraints)
Note regarding format of overlaps
- The format of overlaps is identical to the optional argument opts_pcon.overlaps in
procrustes_consensus.
See also: procrustes_consensus.
Source code in src/utils/overlap_heuristics.m
pairs2chains(pairs)
chains=pairs2chains(pairs) converts pairs of tokens to chains of tokens
For example, the pairs [a b;c d;a e;a f;c f] are converted to the chains {[a b],[e a f],[d c f]}. The pairs are un-ordered, and must be unique. This is useful for graphics: rather than connect multiple pairs of points with each pair connected as separate line objects, one can instead connect them with a smaller number of line objects, one for each chain.
This likely could be optimized; here the algorithm is just to extend chains until there is no unused node. There is no attmept to merge chains, e.g., by splicing together intersecting loops.
Input arguments:
-
pairs(int 2-D array) –a 2-column array of the pairs; each token is a unique integer
Output arguments:
-
chains(cell array) –a cell array of vectors of chains; paired tokens are adjacent in exactly one chain
Source code in src/utils/pairs2chains.m
persp_apply(a, b, c, x)
y=persp_apply(a,b,c,x) applies a perspective (projective) transformation to one or more vectors
Input arguments:
-
a(float 2-D array) –array of size [dimx, dimy], affine component of the transformation
-
b(float 1-D array) –array of size [ 1, dimy], offset component of the transformation
-
c(float 1-D array) –array of size [dimx, 1], perspective component of the transformation
-
x(float 2-D array) –array of size [npts, dimx], the (row) vectors to be transformed; npts is the number of vectors to be transformed
Output arguments:
-
y(float 2-D array) –array of size [npts, dimy], its row vectors are the results of transformation
How the transformation is defined
Each row of x is considered as a homogeneous vector with an augmented coordinate 1 at the end, creating an array of size [npts, dimx+1].
A matrix T, of size [dimx+1, dimy+1] is formed with a in its upper left, b in its lower left, c in its upper right, and 1 in its lower right.
X is then post-multiplied by T, Y=XT.
Y is a homogeneous vector. y is the rows of Y, with each row divided by the final element.
T only matters up to homogeneity, but its lower right element is fixed at 1.
If c is zero, this is an affine transformation.
If c and b are zero, this is a linear transformation.
See also: persp_xform_find, persp_ssqdif, persp_fit, persp_ssqdif_fit.
Source code in src/utils/persp_apply.m
persp_fit(c, x, y)
[a,b]=persp_fit(c,x,y) fits a projective transformation, assuming a vector for the perspective component
Transformation parameters a,b, and c are described in persp_apply.
Input arguments:
-
c(float 1-D array) –array of size [dimx, 1], perspective component of the transformation
-
x(float 2-D array) –array of size [npts, dimx], the (row) vectors to be transformed; npts is the number of vectors to be transformed
-
y(float 2-D array) –array of size [npts, dimy], its row vectors are to be fit by applying the transformation to x
Output arguments:
-
a(float 2-D array) –array of size [dimx, dimy], affine component of the transformation
-
b(float 1-D array) –array of size [ 1, dimy], offset component of the transformation
See also: persp_xform_find, persp_apply, persp_ssqdif, persp_ssqdif_fit.
Source code in src/utils/persp_fit.m
persp_ssqdif(a, b, c, x, y)
[ssq,y_fit]=persp_ssqdif(a,b,c,x,y) determines the deviation between a projective transformation and target values
Transformation parameters a,b, and c are described in persp_apply.
Input arguments:
-
a(float 2-D array) –array of size [dimx, dimy], affine component of the transformation
-
b(float 1-D array) –array of size [ 1, dimy], offset component of the transformation
-
c(float 1-D array) –array of size [dimx, 1], perspective component of the transformation
-
x(float 2-D array) –array of size [npts, dimx], the (row) vectors to be transformed; npts is the number of vectors to be transformed
-
y(float 2-D array) –array of size [npts, dimy], its row vectors are to be fit by applying the transformation to x
Output arguments:
-
ssq(float) –sum of squared differences between y and y_fit
-
y_fit(float 2-D array) –array of size [npts, dimy], the fitted values, i.e., the results of applying the fitted transformation to x
See also: persp_xform_find, persp_apply, persp_fit, persp_ssqdif_fit.
Source code in src/utils/persp_ssqdif.m
persp_ssqdif_fit(c, x, y)
[ssq,y_fit,a,b]=persp_ssqdif_fit(c,x,y) fits a projective transformation, assuming a perspective component, and finds the deviation between target and fitted values
Transformation parameters a,b, and c are described in persp_apply.
Input arguments:
-
c(float 1-D array) –array of size [dimx, 1], perspective component of the transformation
-
x(float 2-D array) –array of size [npts, dimx], the (row) vectors to be transformed; npts is the number of vectors to be transformed
-
y(float 2-D array) –array of size [npts, dimy], its row vectors are to be fit by applying the transformation to x
Output arguments:
-
ssq(float) –sum of squared differences between y and y_fit
-
y_fit(float 2-D array) –array of size [npts, dimy], the fitted values, i.e., the results of applying the fitted transformation to x
-
a(float 2-D array) –array of size [dimx, dimy], affine component of the transformation
-
b(float 1-D array) –array of size [ 1, dimy], offset component of the transformation
See also: persp_xform_find, persp_apply, persp_fit, persp_ssqdif.
Source code in src/utils/persp_ssqdif_fit.m
persp_xform_find(x, y, opts)
[persp,y_fit,opts_used]=persp_xform_find(x,y,opts) fits a projective transformation
Input arguments:
-
x(float 2-D array) –array of size [npts, nd], the (row) vectors to be transformed; npts is the number of vectors to be transformed
-
y(float 2-D array) –array of size [npts, nd], its row vectors are the to be fit by applying the transformatoin to x
-
opts(struct) –an options structure, may be omitted, with fields
method(char) – optimization method to use, can be 'fmin','oneshot','best'; default is 'oneshot' but this is overridden to 'best' when used by rs software; see note below regarding optimization methodsif_cycle(int) – relevant if opts.method='oneshot' or 'best'; see note below regarding optimization methodsfmin_opts(struct) – relevant if opts_method='fmin' or 'best; see note below regarding optimization methods
Output arguments:
-
persp(float 2-D array) –array of size [nd+1 nd+1] specifying the transformation; persp*[x ones(npts,1)] are the homogeneous coordinates cooresponding to y
-
y_fit(float 2-D array) –array of size [npts nd], the fitted values, i.e., the mapping of x via persp (see
persp_applyfor further details) -
opts_used(struct) –
Optimization methods
- 'fmin': an iterative method: An initial specifier of the perspective component (c in
persp_apply) is guessed. Based on c, the other components of the transformation (a and b inpersp_apply) are determined by linear regresssion, yielding a squared-error residual. The residual is then minimized by adjusting c via MATLAB's fmin, which is called with the options in opts.fmin_opts - 'oneshot': This is an implementation of method 2 of The method Z. Zhang, Estimating Projective Transformation Matrix (Collineation, Homography), Microsoft Research Techical Report MSR-TR-2010-63, November 1993; Updated May 29, 2010. It is most apprpriate when the transformation is highly overdetermined, i.e, when there are a large number of data points. If opts.if_cycle=1 (default is 0), this cycles through assignments of which data point is treated as the first point; the one that yields the best fit is returned in opts_used.best_point.
- 'best': Methods 'fmin' and 'oneshot' are both are used, and the results of the method that yields the smallest squared-error residuals is returned
See also: filldefault, persp_ssqdif, persp_ssqdif_fit.
Source code in src/utils/persp_xform_find.m
procrustes_compat(t)
t_new=procrustes_compat(t) converts the fieldnames produced by procrustes_consensus to names compatible with transformation structures
Input arguments:
-
t(struct) –a structure with fields 'scaling', 'orthog', and 'translation'
Output arguments:
-
t_new(struct) –a structure with fields renamed 'b','T','c'
Default values
If 'scaling' is unspecified in 't', b is set to 1 in t_new.
If 'translation' is unspecified in t, 'c' is set to zeros(size(orthog,2)) in t_new
See also: filldefault, procrustes_consensus.
Source code in src/utils/procrustes_compat.m
procrustes_consensus(z, opts_pcon)
[consensus,znew,ts,details,opts_pcon_used]=procrustes_consensus(z,opts_pcon) carries out a Procrustes consensus calculation
This algorithm generalizes MATLAB's procrustes tomore than two datasets, allowing for missig values (indicated by NaNs), eliminating translations, and creation of a consensus that is of higher dimension than any of the components, by zero-padding z along dimension 2.
If called with no arguments, the default settings for opts_pcon are returned.
Input arguments:
-
z(float 3-D array) –input data, size is [npts nds nsets] where npts is the number of points, nds is the number of dimensions, and nsets is the number of datasets
-
opts_pcon(struct) –options struture, may be omitted, with fields
initialize_set(int or char) – method for initialization and alignment on each iteration; default is 1- If in [1:nsets]: use (z(:,:,intialize_set)) for initial guess and alignment; if this set of coordinates has no overlap, use the first set of coordinates after it that does
-
if 'pca','pca_center','pca_nocenter': use first nds principal components across all datasets for initial guess and alignment
- 'pca_center': replace NaN's by mean and then center prior to PCA
- 'pca_nocenter': replace NaN's by mean and do not center prior to PCA
- 'pca': replace NaN's by mean and center if allow_offset=1, do not center if allow_offset=0
-
If 0: specify initial guess and alignment explicitly with the fields
initial_guess(float 2-D array) – array of size [npts nds] for initial guess; if empty ([]), then normally distributed random quantities,alignment(float 2-D array) – array of size [npts nds] for alignment; if empty ([]), use initial_guess
if_initpca_rot(int) – relevant only if initialize_set='pca_center','pca_nocenter', or 'pca'; default is 1- 1 rotates the initial guess into its principal components, best if data are not zero-padded
- 0 does not rotate the initial guess into its initial components, best if the data are zero-padded to access higher dimensions
max_niters(int) – maximum number of iterations; default is 100max_rmstol(float) – rms tolerance for termination, as rms change in all coordinates of consensus, default is 10-5exclude_nan(int) – 1 to exclude NaN values when computing overlaps, 0 to not exclude; default is 1overlaps(int 2-D array) – array of size [npts nsets]; 1 indicates which points should be included, 0 to exclude. If omitted or empty (default), it is computed based on exclude_nanif_justcheck(int) – 1 to just check if overlaps are sufficient, 0 for full computation; default is 0; see note below rearding algorihtm.
Allowed transformations
Initialization and termination
Treatment of overlaps
Output arguments:
-
consensus(float 2-D array) –[npts ndims]: the consensus data
-
znew(float 3-D array) –[npts ndims nsets]: the original data, after transformation to the consensus
-
ts(cell 1-D array) –the transformations. They act as follows: znew(:,:,iset)=ts{iset}.scaling*z(:,:,iset)*ts{iset}.orthog+repmat(ts{iset}.translation,npts,1). These variable names can be converted to MATLAB's conventions via
procrustes_compat. -
details(struct) –details of convergence, with fields
- ts_cum{k}{iset} is the cumulative transformation found for dataset iset at iteration k
- consensus(:,:,k) is the consensus found at iteration k
- z(:,:,iset,k) is the best fit of each dataset at iteration k
- rms_change(k) is the rms change at iteration k
- rms_dev(iset,k) is the rms deviation between all fitted points in dataset iset and the consensus at iteration k (points without overlaps are omitted), per coordinate
zz_check_diff(k+1,iset) – , are computatooinal checks at each iteration, should be neaer zero- warnings: warnings if not enough overlaps
overlap_pairs(iset1,iset2) – number of points that overlap between datasets 1 and 2overlap_totals(ipt) – number of overlaps at each data pointinitialize_use(ipt,1) – which dataset is used to initialize each point (if initialize_set>0)
-
opts_pcon_used(struct) –opts_pcon, with options used filled in
The algorithm
Initialization: guess a consensus via one of the methods specified by initialize_set
Iteration: - Align all the datasets to the tentative consensus, using settings in opts_pcon for scale, reflection, and offset - Set the new tentative consensus to be the point-by-point centroid of each of the component dataasets, following the above alignment - Align the tentative consensus as specified by opts_pcon.alignment, to prevent drift
Terminate after coordinates have not changed within tolerance of opts_pcon.max_rmstol
As a screen for whether there is sufficient overlap between the datasets,
isgraphc is used; if the overlap graph is disconnected, a consensus alignment should not be attempted. But note that connectivity of the overlap graph is not sufficient to
guarantee stability, as multiple points (depending on the dimension to be fit, and the number of datasets that overlap) are needed to determine a
transformation. Overlap details are in details.overlap_pairs and details.overlap_totals .
See also: procrustes_compat, isgraphc.
Source code in src/utils/procrustes_consensus.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
rmsubfield(s, fns)
r=rmsubfield(s,fns) removes a (possibly deeply) nested subfield
Input arguments:
-
s(struct) –a structure
-
fns(cell array) –field names, fns={n1, n2,..., nk}
Output arguments:
-
r(struct) –s, with s.(n1).(n2). ... .(nk) removed
Notes
If any of the subfields are not present, r=s.
Subfield arrays not supported.
Uses recursion:
- k>=2: rmsubfield(s,{n1, n2,..., nk})=setfield(s.(n1),rmsubfield(s.(n1),{n2,..., nk}))
- k=1: rmsubfield(s,{n1, n2,..., nk})=rmfield(s,n1)
See also: SETFIELD, RMFIELD, getsubfield.
Source code in src/utils/rmsubfield.m
setfields(oldstruct, cfields, cvals)
newstruct=setfields(oldstruct,cfields,cvals) sets multiple fields of a structure
Input arguments:
-
oldstruct(struct) –structure, may be empty
-
cfields(cell array of char) –field names
-
cvals(cell array) –field values
Output arguments:
-
newstruct(struct) –oldstruct, with each field cfields{k} set equal to cvals{k}
Source code in src/utils/setfields.m
surf_augvec(varargin)
h=surf_augvec plots a surface, extending MATLAB's surf to cases inwhich the surface to be plotted has a dimension of length 1.
Input arguments:
-
varargin(float array or sequence of float arrays) –arguments to MATLAB's
surfin one of the following formats- surf_augvec(x,y,z,c), where x and y are the independent variables as 1-D vectors, z is surface height as 2-D array, c is color as 2-D array
- surf_augvec(x,y,z), as above, with c proportional to surface height
- surf_augvec(z,c), as above, with x=[1:size(z,2)] and y=[1:size(z,1)]
- surf_augvec(z), as above, with x=[1:size(z,2)] and y=[1:size(z,1)] and c proportional to surface height
- or any of the above preceded by a handle of the axis to plot into
Output arguments:
-
h(handle) –handle to the surface
Source code in src/utils/surf_augvec.m
zpad(ival, ndigits)
ichars=zpad(ival,ndigits) left-pads a non-negative integer with zeros and creates a string
Input arguments:
-
ival(int) –non-negative integer to pad, should be <=10ndigits
-
ndigits(int) –total number of digits for the string
Output arguments:
-
ichars(char) –the left-padded string
Out-of-range values
No checking is done if ival <0 or >=10ndigits.
ival<0 will return an empty string.
ival>10ndigits will be return only the right-most ndigits characters.