Matlab and then c implementation: Smooth data - matlab

I have some data that is slightly noisy. I want to clean it as well as the derivative. A very simple "filter" such as Y(n)=0.2*X(n)+0.8*Y(n-1) suits me well: in other words, the output is smooth enough. Here is an example with both data and its derivative:
Nevertheless, as it's real-time, I cannot accept a big lag in data. For the derivative, the lag is around 10 iterations: 5 iterations (to get the filtered data) and then another 5 iterations (to get the filtered derivative data).
How can I implement an algorithm in Matlab - in fine, I need a c implementation - that produces a similar result but with very little lag, such as a maximum of 3 iterations EVEN and ESPECIALLY for the derivative.
Here is the Matlab code:
%Here is data input;
data = [5554 5767 5737 5828 6011 6011 6103 6225 6408 6286 6347 6439 6591 6683 6530 6652 6805 7019 7080 7019 6988 6988 6958 6958 6927 6896 6866 6805 6835 6713 6591 6713 6713 6652 6713 6713 6835 6896 6744 6622 6683 6561 6591 6591 6622 6561 6500 6652 6774 6805 6958 7049 7171 7232 7293 7293 7415 7476 7690 8087 8056 7965 8178 8270 8148 8178 8392 8239 8056 8026 7873 7873 7476 7446 7476 7293 7171 7141 7263 7019 7141 6774 6652 6530 6530 6469 6561 6622 6652 6713 6866 6958 6958 7110 6958 7049 6805 6866 6866 6744 7049 6805 6652 6530 6622 6744 6408 6652 6683 6713 6713 6622 6744 6805 6713 6683 6805 6835 6927 6866 6805 6744 7049 7232 7171 7141 7202 7354 7324 7415 7415 7415 7965 8178 8178 8178 8178 7995 7995 7965 7843 7904 7904 7812 7812 7720 7690 7843 7873 7904 8056 7904 7843 7934 7873 7873 7781 7781 7873 7873 7873 7690 7659 7690 7720 7751 7659 7598 7629 7659 7568 7537 7629 7537 7659 7568 7568 7476 7568 7598 7354 7324 7476 7354 7385 7202 7293 7293 6958 6866 6866 6683 6927 6927 6927 7019 7019 7049 7141 7202 7293 7385 7568 7446 7446 7415 7354 7263 7293 7202 7202 7202 7232 7202 7263 7141 7171 7019 7141 7232 7080 7232 7141 7263 6958 7019 7019 6866 6896 6744 6774 6805 6835 6866 6774 6744 6774 6744 6744 6866 6958 6958 7019 6988 6988 6896 6958 7080 7080 7171 7232 7202 7354 7385 7385 7476 7720 7690 7598 7659 7659 7690 7720 7720 7690 7690 7781 7751 7659 7812 7873 7659 7629 7446 7446 7629 7354 7415 7476 7568 7415 7385 7385 7324 7202 7324 7110 6958 7019 7019 7049 6774 7202 6561 6408 6195 5920 5920 5920 5859 5615 5645 5584 5676 5432 5401 5126 5096 5004 5004 4791 4852 4791 4791 4730 4760 4730 4730 4699 4760 4669 4730 4760 4760 4791 4882 4882 4882 4974 4943 4974 5065 5096 5157 5218 5279 5279]';
%Define smooth coefficient
c=0.2;
%Filter data
data_filtered=zeros(size(data),1);
for n=drange(2:size(data))
data_filtered(n,1)=c*data(n)+(1-c)*data_filtered(n-1,1);
end
%Graph both data and filtered data
subplot(2,1,1);
plot([1:size(data)], data, [1:size(data)], data_filtered);
%Calculate derivative data. Delta time is constant.
for n=drange(2:size(data_filtered))
data_derivative(n,1)=data(n)-data(n-1,1);
end
%Calculate derivative based on filtered data. Delta time is constant.
for n=drange(2:size(data_filtered))
data_filtered_derivative(n,1)=data_filtered(n)-data_filtered(n-1,1);
end
%Filter derivative (which is based on filtered data)
data_filtered_derivative_filtered=data_filtered_derivative;
for n=drange(2:size(data_filtered_derivative))
data_filtered_derivative_filtered(n,1)=c*data_filtered_derivative(n)+(1-c)*data_filtered_derivative_filtered(n-1,1);
end
%Graph both derivative data and filtered derivative data
subplot(2,1,2);
plot([1:size(data_derivative)], data_derivative, [1:size(data_derivative)], data_filtered_derivative_filtered);

If you want an excellent, low-lag filter it seems something like Jurik JMA might be for you. It is probably pretty expensive (and definitely not free) but the paper might give you ideas on other (possibly free) algorithms.
I have not tested that algorithm, I have just found it and liked the pictures.

Related

smooth filtering shifts my original signal?

Here is my code:
sigma = 10;
sz = 20;
x = linspace(-sz / 2, sz / 2-1, sz);
gf = exp(-x .^ 2 / (2 * sigma ^ 2));
gf = gf / sum (gf); % normalize
f_filter = cconv(gf,f,length(f));
Basically I am Gaussian filtering original signal f. However, when I look at the filtered signal f_filter, there is a shift comparing the original signal f (See attached figure). I am not sure why this is happening. I would like to only smooth but not shift the orginal signal. Please help. Thanks.
my original signal f is here:
-0.0311
-0.0462
-0.0498
-0.0640
-0.0511
-0.0522
-0.0566
-0.0524
-0.0478
-0.0482
-0.0516
-0.0435
-0.0417
-0.0410
-0.0278
-0.0079
-0.0087
-0.0029
0.0105
0.0042
0.0046
0.0107
0.0119
0.0177
0.0077
0.0138
0.0114
0.0103
0.0089
0.0122
0.0122
0.0118
0.0041
0.0047
0.0062
0.0055
0.0033
0.0096
0.0062
-0.0013
0.0029
0.0112
0.0069
0.0160
0.0127
0.0131
0.0039
0.0116
0.0078
0.0018
0.0023
0.0133
0.0140
0.0135
0.0098
0.0100
0.0133
0.0131
0.0086
0.0114
0.0131
0.0175
0.0137
0.0157
0.0040
0.0136
0.0009
0.0049
0.0157
0.0104
0.0038
0.0039
0.0029
0.0126
0.0044
0.0055
0.0040
0.0091
-0.0023
0.0107
0.0151
0.0115
0.0135
0.0160
0.0071
0.0098
0.0094
0.0072
0.0079
0.0055
0.0155
0.0107
0.0108
0.0085
0.0099
0.0055
0.0078
0.0027
0.0121
0.0077
0.0062
0.0021
-0.0019
-0.0003
-0.0022
0.0059
0.0099
0.0114
0.0069
0.0038
0.0020
-0.0031
0.0024
-0.0025
-0.0004
0.0041
0.0059
0.0018
0.0033
0.0130
0.0131
0.0076
0.0084
0.0029
0.0086
0.0078
0.0054
0.0121
0.0101
0.0132
0.0115
0.0074
0.0070
0.0088
0.0017
-0.0003
-0.0060
0.0078
0.0100
0.0044
0.0017
0.0027
0.0062
0.0029
-0.0035
0.0032
0.0060
-0.0035
0.0081
0.0027
0.0043
0.0013
0.0049
0.0119
0.0273
0.0363
0.0435
0.0432
0.0357
0.0424
0.0318
0.0341
0.0354
0.0325
0.0263
0.0320
0.0312
0.0345
0.0407
0.0378
0.0376
0.0334
0.0381
0.0428
0.0375
0.0431
0.0403
0.0395
0.0308
0.0150
0.0006
0.0054
0.0002
0.0090
0.0075
0.0051
0.0067
0.0062
0.0108
0.0059
0.0095
0.0065
0.0087
0.0056
0.0136
0.0057
0.0079
0.0107
0.0106
0.0041
0.0032
0.0106
0.0091
0.0082
0.0025
0.0124
0.0035
0.0034
0.0097
0.0034
0.0050
0.0119
0.0087
0.0081
0.0118
0.0088
0.0050
0.0050
0.0057
0.0118
0.0122
0.0207
0.0112
0.0125
0.0083
0.0125
0.0140
0.0147
0.0237
0.0206
0.0141
0.0164
0.0189
0.0189
0.0136
0.0183
0.0195
0.0209
0.0154
0.0211
0.0254
0.0163
0.0249
0.0236
0.0262
0.0278
0.0285
0.0275
0.0212
0.0277
0.0211
0.0248
0.0289
0.0240
0.0266
0.0479
0.1744
0.4070
0.6818
0.8811
0.9859
0.9347
0.8441
0.7625
0.6396
0.4724
0.3639
0.3406
0.3406
0.3363
0.3318
0.3251
0.3287
0.3135
0.3122
0.3058
0.3103
0.3012
0.2974
0.2995
0.2941
0.2981
0.2968
0.2958
0.2938
0.2929
0.2926
0.2942
0.2982
0.2898
0.2940
0.2927
0.2950
0.2899
0.2979
0.2915
0.2961
0.2921
0.2931
0.2989
0.2941
0.2977
0.3041
0.3042
0.3086
0.3048
0.3069
0.3055
0.3123
0.3138
0.3128
0.3115
0.3092
0.3174
0.3152
0.3106
0.3080
0.3166
0.3109
0.3103
0.3135
0.3101
0.3133
0.3147
0.3044
0.2980
0.2972
0.3013
0.2980
0.3069
0.3932
0.6593
0.8921
1.1071
1.2763
1.3947
1.5076
1.6278
1.7452
1.7993
1.8287
1.8470
1.8957
1.9408
1.9791
2.0272
2.0686
2.0974
2.1335
2.1790
2.2134
2.2545
2.2903
2.3163
2.3585
2.3739
2.4126
2.4503
2.4787
2.5198
2.5447
2.5950
2.6228
2.6410
2.6812
2.7123
2.7557
2.8584
3.2480
3.5315
3.6808
3.7632
3.7471
3.7283
3.6692
3.6718
3.7756
3.9672
4.0376
3.9092
3.7276
3.6586
3.5948
3.6392
3.5671
3.6003
3.6194
3.6350
3.6624
3.6855
3.6958
3.9105
4.3880
5.1342
5.6176
6.3206
7.0392
7.3767
7.5715
7.6516
7.6469
7.5871
7.4591
7.6004
7.5532
7.3601
7.1487
5.9728
4.8974
4.5850
4.4268
4.3352
4.2887
4.3376
4.3182
4.2909
4.2777
4.2548
4.2677
4.2511
4.2817
4.3847
4.4418
4.4696
4.4932
4.4998
4.5151
4.5096
4.5278
4.5139
4.5020
4.4561
4.4067
4.3841
4.3638
4.3750
4.4366
4.5258
4.6565
4.6485
4.5836
4.5183
4.4583
4.3747
4.3509
4.2938
4.2823
4.2844
4.3135
4.3262
4.3255
4.2568
4.2011
4.1832
4.2278
4.2445
4.2409
4.2784
4.2917
4.3035
4.3015
4.3209
4.3204
4.3356
4.3287
4.3260
4.3483
4.3710
4.3798
4.3802
4.3805
4.5162
4.6906
5.0826
5.6588
6.0137
6.2436
6.5361
7.0790
7.6106
7.6410
7.4120
7.4535
7.2476
7.2596
7.1012
7.0986
6.9395
6.5633
5.8438
4.9434
4.6750
4.4320
4.3063
4.2096
4.0193
3.9698
4.0055
4.0218
4.0426
4.0688
4.0650
3.9793
3.9787
3.9766
3.9981
4.0405
4.0165
4.0290
4.0923
4.0897
4.0615
4.0258
4.0008
4.0274
4.0553
4.0646
4.0442
4.0477
3.9986
4.0354
4.0718
4.0563
4.0189
3.8631
3.8144
3.7736
3.8055
3.9730
4.0299
4.0148
3.8265
3.4675
3.3020
3.2474
3.2338
3.1986
3.1680
3.1289
3.0944
3.0523
3.0094
2.9510
2.9246
2.9057
2.8805
2.8545
2.8245
2.7690
2.7236
2.6833
2.6443
2.5969
2.5415
2.4684
2.4214
2.3699
2.3293
2.2513
2.1963
2.1285
2.0700
2.0209
1.9575
1.8658
1.6996
1.5120
1.4020
1.3087
1.2166
1.1441
1.0774
1.0226
0.9809
0.9448
0.8526
0.6915
0.4491
0.2842
0.2582
0.2570
0.2568
0.2609
0.2632
0.2581
0.2552
0.2539
0.2527
0.2578
0.2672
0.2701
0.2655
0.2658
0.2688
0.2761
0.2767
0.2738
0.2774
0.2801
0.2817
0.2803
0.2830
0.2828
0.2876
0.2952
0.2985
0.3016
0.3092
0.3130
0.3153
0.3182
0.3304
0.3471
0.3416
0.3476
0.3497
0.3453
0.3398
0.3448
0.3563
0.3511
0.3502
0.3481
0.3519
0.3573
0.3544
0.3512
0.3489
0.3499
0.3470
0.3533
0.3409
0.3556
0.3474
0.3435
0.3460
0.3519
0.3447
0.3395
0.3488
0.3473
0.3453
0.3433
0.3484
0.3526
0.3494
0.3607
0.3694
0.4126
0.4604
0.5004
0.5163
0.5328
0.5432
0.5506
0.5485
0.5605
0.5586
0.5622
0.5727
0.5804
0.5797
0.5666
0.5700
0.5696
0.5722
0.5715
0.5656
0.5572
0.5264
0.5156
0.5473
0.6286
0.7503
0.8715
0.8825
0.7507
0.5421
0.2869
0.1091
0.0423
0.0326
0.0343
0.0256
0.0231
0.0281
0.0298
0.0229
0.0283
0.0279
0.0270
0.0300
0.0245
0.0360
0.0280
0.0270
0.0232
0.0276
0.0270
0.0237
0.0197
0.0193
0.0172
0.0140
0.0093
0.0244
0.0226
0.0192
0.0145
0.0124
0.0167
0.0182
0.0111
0.0147
0.0081
0.0151
0.0130
0.0113
0.0131
0.0067
0.0028
0.0064
0.0069
0.0082
0.0075
0.0098
-0.0008
0.0037
0.0019
0.0060
0.0057
0.0033
0.0079
0.0122
0.0091
0.0067
-0.0038
0.0033
0.0013
0.0011
0.0034
0.0051
0.0009
-0.0001
-0.0005
0.0098
-0.0003
0.0067
0.0038
0.0106
0.0000
0.0126
0.0134
0.0090
0.0116
0.0083
0.0101
0.0152
0.0010
0.0068
0.0008
0.0053
0.0090
0.0087
0.0085
0.0054
0.0089
0.0077
0.0064
0.0046
0.0058
0.0025
0.0132
0.0088
0.0043
0.0052
0.0087
0.0122
0.0023
0.0066
0.0093
0.0042
0.0042
0.0138
0.0051
-0.0055
-0.0002
0.0048
0.0063
0.0076
0.0016
-0.0005
0.0086
0.0043
-0.0016
0.0100
0.0097
0.0042
0.0092
0.0051
0.0029
0.0044
0.0033
0.0073
0.0093
0.0077
0.0093
0.0021
0.0026
0.0093
0.0068
0.0039
0.0068
0.0041
0.0053
0.0037
0.0075
0.0016
0.0000
-0.0005
0.0073
0.0076
0.0049
0.0046
0.0087
0.0106
0.0072
0.0085
0.0036
0.0044
0.0043
0.0201
0.0076
0.0075
0.0134
0.0050
0.0071
0.0032
0.0055
0.0085
0.0046
0.0023
-0.0020
0.0027
0.0060
0.0066
0.0067
0.0014
0.0166
0.0067
0.0024
0.0072
0.0062
0.0081
0.0035
0.0077
0.0101
0.0045
0.0034
0.0144
0.0078
0.0065
0.0093
0.0181
0.0028
0.0050
0.0034
0.0063
0.0150
0.0035
0.0022
0.0079
0.0034
0.0110
0.0075
0.0058
0.0085
0.0152
0.0089
0.0060
0.0017
0.0041
0.0091
0.0072
-0.0109
0.0036
0.0063
0.0080
0.0037
0.0086
0.0097
0.0088
0.0016
0.0057
0.0059
0.0139
0.0061
0.0009
0.0059
0.0126
0.0117
0.0003
0.0060
0.0075
0.0073
0.0080
0.0154
0.0136
0.0121
0.0179
0.0150
0.0125
Instead of doing
f_filter = cconv(gf,f,length(f));
this does the trick:
f_filter = conv(gf,f);
f_filter = f_filter(sz/2+1:end-sz/2+1);
As suggested by #AnderBiguri you can use the option 'same' in your convolution fonction to preserve the original size of your array.
But if you apply a convolution with your normalized gaussian filter gf you will obtain a border effect.
To avoid the border effect you can apply the following tricks:
gf = exp(-x .^ 2 / (2 * sigma ^ 2)); %do not normalize gf now
f_filter = conv(f,gf,'same')./conv(ones(length(f),1),gf,'same') %normalization taking into account the lenght of the convolution
For example I've just transformed f into f = f+3
If we do not take into account the border effect we will obtain:

Scala build crashed

I have updated scala and sbt version to 2.12.0 and 0.13.8 respectively. Now every build fails with errors:
java.lang.VerifyError: Uninitialized object exists on backward branch 209
Exception Details:
Location:
scala/collection/immutable/HashMap$HashTrieMap.split()Lscala/collection/immutable/Seq; #249: goto
Reason:
Error exists in the bytecode
Bytecode:
0000000: 2ab6 0057 04a0 001e b200 afb2 00b4 04bd
0000010: 0002 5903 2a53 c000 b6b6 00ba b600 bec0
0000020: 00c0 b02a b600 31b8 003b 3c1b 04a4 015e
0000030: 1b05 6c3d 2a1b 056c 2ab6 0031 b700 c23e
0000040: 2ab6 0031 021d 787e 3604 2ab6 0031 0210
0000050: 201d 647c 7e36 05bb 0014 59b2 00b4 2ab6
0000060: 0033 c000 b6b6 00c6 b700 c91c b600 cd3a
0000070: 0619 06c6 001a 1906 b600 d1c0 007d 3a07
0000080: 1906 b600 d4c0 007d 3a08 a700 0dbb 00d6
0000090: 5919 06b7 00d9 bf19 073a 0919 083a 0abb
00000a0: 0002 5915 0419 09bb 0014 59b2 00b4 1909
00000b0: c000 b6b6 00c6 b700 c903 b800 df3a 0e3a
00000c0: 0d03 190d b900 e301 0019 0e3a 1136 1036
00000d0: 0f15 0f15 109f 0027 150f 0460 1510 190d
00000e0: 150f b900 e602 00c0 0005 3a17 1911 1917
00000f0: b800 ea3a 1136 1036 0fa7 ffd8 1911 b800
0000100: eeb7 005c 3a0b bb00 0259 1505 190a bb00
0000110: 1459 b200 b419 0ac0 00b6 b600 c6b7 00c9
0000120: 03b8 00df 3a13 3a12 0319 12b9 00e3 0100
0000130: 1913 3a16 3615 3614 1514 1515 9f00 2715
0000140: 1404 6015 1519 1215 14b9 00e6 0200 c000
0000150: 053a 1819 1619 18b8 00f1 3a16 3615 3614
0000160: a7ff d819 16b8 00ee b700 5c3a 0cb2 00f6
0000170: b200 b405 bd00 0259 0319 0b53 5904 190c
0000180: 53c0 00b6 b600 bab6 00f9 b02a b600 3303
0000190: 32b6 00fb b0
Stackmap Table:
same_frame(#35)
full_frame(#141,{Object[#2],Integer,Integer,Integer,Integer,Integer,Object[#105]},{})
append_frame(#151,Object[#125],Object[#125])
full_frame(#209,{Object[#2],Integer,Integer,Integer,Integer,Integer,Object[#105],Object[#125],Object[#125],Object[#125],Object[#125],Top,Top,Object[#20],Object[#55],Integer,Integer,Object[#103]},{Uninitialized[#159],Uninitialized[#159],Integer,Object[#125]})
full_frame(#252,{Object[#2],Integer,Integer,Integer,Integer,Integer,Object[#105],Object[#125],Object[#125],Object[#125],Object[#125],Top,Top,Object[#20],Object[#55],Integer,Integer,Object[#103]},{Uninitialized[#159],Uninitialized[#159],Integer,Object[#125]})
full_frame(#312,{Object[#2],Integer,Integer,Integer,Integer,Integer,Object[#105],Object[#125],Object[#125],Object[#125],Object[#125],Object[#2],Top,Object[#20],Object[#55],Integer,Integer,Object[#103],Object[#20],Object[#55],Integer,Integer,Object[#103]},{Uninitialized[#262],Uninitialized[#262],Integer,Object[#125]})
full_frame(#355,{Object[#2],Integer,Integer,Integer,Integer,Integer,Object[#105],Object[#125],Object[#125],Object[#125],Object[#125],Object[#2],Top,Object[#20],Object[#55],Integer,Integer,Object[#103],Object[#20],Object[#55],Integer,Integer,Object[#103]},{Uninitialized[#262],Uninitialized[#262],Integer,Object[#125]})
full_frame(#395,{Object[#2],Integer},{})
at scala.collection.immutable.HashMap$.scala$collection$immutable$HashMap$$makeHashTrieMap(HashMap.scala:179)
at scala.collection.immutable.HashMap$HashMap1.updated0(HashMap.scala:211)
at scala.collection.immutable.HashMap.$plus(HashMap.scala:59)
at scala.collection.immutable.HashMap.$plus(HashMap.scala:62)
at scala.collection.immutable.Map$Map4.updated(Map.scala:201)
at scala.collection.immutable.Map$Map4.$plus(Map.scala:202)
at scala.collection.immutable.Map$Map4.$plus(Map.scala:180)
at scala.collection.mutable.MapBuilder.$plus$eq(MapBuilder.scala:29)
at scala.collection.mutable.MapBuilder.$plus$eq(MapBuilder.scala:25)
at scala.collection.generic.Growable.$anonfun$$plus$plus$eq$1(Growable.scala:59)
at scala.collection.generic.Growable$$Lambda$19/924699145.apply(Unknown Source)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
at scala.collection.generic.Growable.$plus$plus$eq(Growable.scala:59)
at scala.collection.generic.Growable.$plus$plus$eq$(Growable.scala:50)
at scala.collection.mutable.MapBuilder.$plus$plus$eq(MapBuilder.scala:25)
at scala.collection.generic.GenMapFactory.apply(GenMapFactory.scala:48)
at scala.sys.package$.env(package.scala:61)
at scala.tools.nsc.settings.ScalaSettings.defaultClasspath(ScalaSettings.scala:30)
at scala.tools.nsc.settings.ScalaSettings.defaultClasspath$(ScalaSettings.scala:30)
at scala.tools.nsc.settings.MutableSettings.defaultClasspath(MutableSettings.scala:19)
at scala.tools.nsc.settings.ScalaSettings.$init$(ScalaSettings.scala:60)
at scala.tools.nsc.settings.MutableSettings.<init>(MutableSettings.scala:20)
at scala.tools.nsc.Settings.<init>(Settings.scala:12)
at scala.tools.nsc.Driver.process(Driver.scala:41)
at scala.tools.nsc.Main.process(Main.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at sbt.compiler.RawCompiler.apply(RawCompiler.scala:26)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1$$anonfun$apply$2.apply(AnalyzingCompiler.scala:146)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1$$anonfun$apply$2.apply(AnalyzingCompiler.scala:142)
at sbt.IO$.withTemporaryDirectory(IO.scala:291)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1.apply(AnalyzingCompiler.scala:142)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1.apply(AnalyzingCompiler.scala:139)
at sbt.IO$.withTemporaryDirectory(IO.scala:291)
at sbt.compiler.AnalyzingCompiler$.compileSources(AnalyzingCompiler.scala:139)
at sbt.compiler.ComponentCompiler$$anonfun$compileAndInstall$1.apply(ComponentCompiler.scala:63)
at sbt.compiler.ComponentCompiler$$anonfun$compileAndInstall$1.apply(ComponentCompiler.scala:60)
at sbt.IO$.withTemporaryDirectory(IO.scala:291)
at sbt.compiler.ComponentCompiler.compileAndInstall(ComponentCompiler.scala:60)
at sbt.compiler.ComponentCompiler$$anonfun$getLocallyCompiled$1.apply$mcV$sp(ComponentCompiler.scala:50)
at sbt.IfMissing$Define.apply(ComponentManager.scala:75)
at sbt.ComponentManager.sbt$ComponentManager$$createAndCache$1(ComponentManager.scala:39)
at sbt.ComponentManager$$anonfun$sbt$ComponentManager$$fromGlobal$1$1.apply(ComponentManager.scala:27)
at sbt.ComponentManager$$anonfun$sbt$ComponentManager$$fromGlobal$1$1.apply(ComponentManager.scala:26)
at sbt.ComponentManager$$anon$1.call(ComponentManager.scala:50)
at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:93)
at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:78)
at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:97)
at xsbt.boot.Using$.withResource(Using.scala:10)
at xsbt.boot.Using$.apply(Using.scala:9)
at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:58)
at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:48)
at xsbt.boot.Locks$.apply0(Locks.scala:31)
at xsbt.boot.Locks$.apply(Locks.scala:28)
at sbt.ComponentManager.lock(ComponentManager.scala:50)
at sbt.ComponentManager.lockGlobalCache(ComponentManager.scala:49)
at sbt.ComponentManager.sbt$ComponentManager$$fromGlobal$1(ComponentManager.scala:25)
at sbt.ComponentManager$$anonfun$files$1$$anonfun$apply$2.apply(ComponentManager.scala:44)
at sbt.ComponentManager$$anonfun$files$1$$anonfun$apply$2.apply(ComponentManager.scala:44)
at sbt.ComponentManager.sbt$ComponentManager$$getOrElse$1(ComponentManager.scala:32)
at sbt.ComponentManager$$anonfun$files$1.apply(ComponentManager.scala:44)
at sbt.ComponentManager$$anonfun$files$1.apply(ComponentManager.scala:44)
at sbt.ComponentManager$$anon$1.call(ComponentManager.scala:50)
at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:93)
at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:78)
at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:97)
at xsbt.boot.Using$.withResource(Using.scala:10)
at xsbt.boot.Using$.apply(Using.scala:9)
at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:58)
at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:48)
at xsbt.boot.Locks$.apply0(Locks.scala:31)
at xsbt.boot.Locks$.apply(Locks.scala:28)
at sbt.ComponentManager.lock(ComponentManager.scala:50)
at sbt.ComponentManager.lockLocalCache(ComponentManager.scala:47)
at sbt.ComponentManager.files(ComponentManager.scala:44)
at sbt.ComponentManager.file(ComponentManager.scala:53)
at sbt.compiler.ComponentCompiler.getLocallyCompiled(ComponentCompiler.scala:50)
at sbt.compiler.ComponentCompiler.apply(ComponentCompiler.scala:36)
at sbt.compiler.ComponentCompiler$$anon$1.apply(ComponentCompiler.scala:23)
at sbt.compiler.AnalyzingCompiler.loader(AnalyzingCompiler.scala:112)
at sbt.compiler.AnalyzingCompiler.getInterfaceClass(AnalyzingCompiler.scala:117)
at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:98)
at sbt.compiler.AnalyzingCompiler.newCachedCompiler(AnalyzingCompiler.scala:56)
at sbt.compiler.AnalyzingCompiler.newCachedCompiler(AnalyzingCompiler.scala:51)
at sbt.compiler.CompilerCache$$anon$2.apply(CompilerCache.scala:47)
at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:39)
at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply$mcV$sp(MixedAnalyzingCompiler.scala:51)
at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply(MixedAnalyzingCompiler.scala:51)
at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply(MixedAnalyzingCompiler.scala:51)
at sbt.compiler.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:75)
at sbt.compiler.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:50)
at sbt.compiler.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:65)
at sbt.compiler.IC$$anonfun$compileInternal$1.apply(IncrementalCompiler.scala:160)
at sbt.compiler.IC$$anonfun$compileInternal$1.apply(IncrementalCompiler.scala:160)
at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:66)
at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:64)
at sbt.inc.IncrementalCommon.cycle(IncrementalCommon.scala:31)
at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:62)
at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:61)
at sbt.inc.Incremental$.manageClassfiles(Incremental.scala:89)
at sbt.inc.Incremental$.compile(Incremental.scala:61)
at sbt.inc.IncrementalCompile$.apply(Compile.scala:54)
at sbt.compiler.IC$.compileInternal(IncrementalCompiler.scala:160)
at sbt.compiler.IC$.incrementalCompile(IncrementalCompiler.scala:138)
at sbt.Compiler$.compile(Compiler.scala:128)
at sbt.Compiler$.compile(Compiler.scala:114)
at sbt.Defaults$.sbt$Defaults$$compileIncrementalTaskImpl(Defaults.scala:814)
at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:805)
at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:803)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
at sbt.std.Transform$$anon$4.work(System.scala:63)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.Execute.work(Execute.scala:235)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I am using jdk 1.8.0, OS X 10.11.6. Here code example:
object Main {
def main(args: Array[String]) {
println("test")
}
}
The same code builded fine with scala 2.10
UPD: build.sbt for 2.12 version
name := "hello_world_3"
version := "1.0"
scalaVersion := "2.12.0"
Problem was in minor JDK version. Scala 2.12 require's newer version of JDK then 1.8.0_111. So after JDK upgrade everything work. Thanks to #rumoku

Reshaping 3D array to 2D

Check out following toy example:
m = 3;
n = 3;
Y = rand(m,n,2);
for example gives me
y(:,:,1) =
0.8314 0.3993 0.6569
0.8034 0.5269 0.6280
0.0605 0.4168 0.2920
y(:,:,2) =
0.4317 0.1672 0.1981
0.0155 0.1062 0.4897
0.9841 0.3724 0.3395
now when I reshape it using
reshape(Y,m*n,2)
it disturbs the order and gives me,
0.8314 0.4317
0.8034 0.0155
0.0605 0.9841
0.3993 0.1672
0.5269 0.1062
0.4168 0.3724
0.6569 0.1981
0.6280 0.4897
0.2920 0.3395
because here 2nd row should be
0.3993 0.1672
this can be crosschecked before reshaping by
Y(1,1,:)
Y(1,2,:)
etc.
The order changes.
PS : I have huge data to be fed in Neural network and this affects the way my weights are being multiplied.
Add in permute there and then reshape, like so -
reshape(permute(y,[2,1,3]),[],size(y,3))
Sample run -
>> y
y(:,:,1) =
0.8314 0.3993 0.6569
0.8034 0.5269 0.628
0.0605 0.4168 0.292
y(:,:,2) =
0.4317 0.1672 0.1981
0.0155 0.1062 0.4897
0.9841 0.3724 0.3395
>> reshape(permute(y,[2,1,3]),[],size(y,3))
ans =
0.8314 0.4317
0.3993 0.1672
0.6569 0.1981
0.8034 0.0155
0.5269 0.1062
0.628 0.4897
0.0605 0.9841
0.4168 0.3724
0.292 0.3395

Matlab data sampler that weights the outputs to binary (0,1)

a sample probability matrix:
ans =
0.1444 0.0456 0.0138 0.0126 0.0116 0.0107 0.0052
0.1444 0.0456 0.0138 0.0126 0.0116 0.0107 0.0052
0.1222 0.0386 0.0116 0.0106 0.0098 0.0091 0.0044
0.1444 0.0456 0.0138 0.0126 0.0116 0.0107 0.0052
0.1222 0.0386 0.0116 0.0106 0.0098 0.0091 0.0044
0.1889 0.0596 0.0180 0.0164 0.0151 0.0140 0.0067
0.1333 0.0421 0.0127 0.0116 0.0107 0.0099 0.0048
I have used dataSample and randSample to sample 128 time from my data which has A=(7,7) size in matlab:
datasample(A,128)
ans =
0.1333 0.0421 0.0127 0.0116 0.0107 0.0099 0.0048
0.1222 0.0386 0.0116 0.0106 0.0098 0.0091 0.0044
0.1889 0.0596 0.0180 0.0164 0.0151 0.0140 0.0067
0.1889 0.0596 0.0180 0.0164 0.0151 0.0140 0.0067
0.1333 0.0421 0.0127 0.0116 0.0107 0.0099 0.0048
0.1444 0.0456 0.0138 0.0126 0.0116 0.0107 0.0052
0.1222 0.0386 0.0116 0.0106 0.0098 0.0091 0.0044
...
However, I am interested in having those 128 sample of 7 (128,7) in binary format with two discrete values of 0 and 1:
[1 1 1 0 1 0 1]
I can write a loop and round-down/up those values to 0 and 1 with certain thresholds (i.e. 0.5), but that for sure will be noisy. Is there a function that can output the sampling in binary (0,1) in Matlab ?

predict value of curve in matlab

Suppose I have the following vector of points:
X=[ 0.401 0.398 0.395 0.392 0.388 0.384 0.381 0.377 0.373 0.368 0.364 0.359 0.354 0.349 0.344 0.339 0.334 0.328 0.322 0.316 0.310 0.304 0.297 0.291 0.284 0.277 0.270 0.263 0.256 0.249 0.242 0.234 0.227 0.220 0.212 0.205 0.198 0.190 0.183 0.176 0.169 0.161 0.154 0.147 0.140 0.134 0.127 0.120 0.113 0.107 0.101 0.094 0.088 0.082 0.076 0.070 0.064 0.059 0.053 0.048 0.042 0.037 0.032 0.027 0.022 0.018 0.013 0.009 0.004 0.000 -0.004 -0.008 -0.012 -0.016 -0.019 -0.023 -0.026 -0.030 -0.033 -0.036 -0.039 -0.042 -0.045 -0.048 -0.050 -0.053 -0.055 -0.058 -0.060 -0.062 -0.064 -0.066 -0.068 -0.070 -0.072 -0.074 -0.076 -0.077 -0.079 -0.080];
Y=[0.347 0.362 0.377 0.393 0.409 0.426 0.442 0.459 0.477 0.494 0.512 0.530 0.548 0.567 0.585 0.604 0.622 0.641 0.659 0.678 0.696 0.715 0.733 0.750 0.768 0.785 0.801 0.817 0.833 0.848 0.863 0.876 0.890 0.902 0.914 0.925 0.935 0.945 0.953 0.961 0.969 0.975 0.981 0.986 0.990 0.993 0.996 0.998 0.999 1.000 1.000 0.999 0.998 0.996 0.994 0.991 0.988 0.984 0.979 0.974 0.969 0.963 0.957 0.951 0.944 0.937 0.930 0.922 0.914 0.906 0.898 0.889 0.881 0.872 0.863 0.855 0.846 0.837 0.827 0.818 0.809 0.800 0.791 0.782 0.773 0.764 0.755 0.747 0.738 0.729 0.721 0.712 0.704 0.696 0.688 0.680 0.672 0.664 0.656 0.649];
When I plot the points X and Y, this is what I get:
I want to calculate the value of 'Width' of the curve W. How can I do that?
It looks like the points are unordered, and so simply subtracting the last point by the first point won't work. What you can do is use max and min on the X array to determine the width:
Width = max(X) - min(X);
It's certainly as simple as that! FWIW, your title says one thing, but your question asks another. Suggest you either edit your question or title for clarity.