Why iOS audio capture callback time interval is not smooth? - ios

I writing my iOS app to record audio.
I called session.setPreferredIOBufferDuration(0.001) to set the duration, and recorded the intervals between two callbacks.
This is data of my iPhone 8:
max = 198 avg = 2.75314 min = 0
======================================================
4 2 2 3 5 3 1 3 6 1
2 2 6 0 5 3 1 3 3 5
1 3 3 2 3 5 1 3 3 3
3 4 1 4 3 2 4 2 3 3
3 3 3 3 2 3 3 3 5 1
3 2 3 3 3 3 3 5 1 3
3 3 3 3 3 3 4 1 3 3
3 3 3 2 3 4 2 3 3 3
3 4 5 0 2 3 3 3 3 3
3 3 3 3 2 3 4 2 3 3
3 3 3 3 3 3 4 2 2 4
3 2 4 2 3 2 4 3 4 2
2 3 3 3 3 2 4 3 5 1
2 4 2 3 2 3 4 3 3 2
4 5 1 2 3 4 2 4 1 3
3 3 3 5 2 2 2 4 2 3
3 3 3 6 0 3 3 3 2 3
3 3 4 2 3 3 2 3 3 3
3 3 3 3 5 1 2 3 3 3
3 3 4 4 1 2 3 3 4 2
3 3 3 3 3 2 3 6 0 3
3 3 4 2 3 3 3 2 5 1
And this is data of my iPhone 7:
max = 246 avg = 2.59249 min = 0
======================================================
3 2 3 2 3 3 5 2 2 3
3 3 3 4 2 2 3 3 3 3
221 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 2 0 0 0
0 0 0 0 0 0 0 1 7 1
1 3 2 3 3 3 3 2 4 4
1 3 4 2 3 3 5 4 0 2
3 5 2 3 2 3 3 4 2 3
2 6 0 4 2 3 3 3 4 3
1 3 3 3 5 3 1 3 3 2
as you see, the max interval is far away from 1ms I set to AudioSession.
and huge numbers form iPhone 7 is appeared much often.
Why iOS don't call my callback smoothly? Can I do any thing, such as set some preference, to get more smooth data?
Thank you.

1) The preferred buffer duration is only a suggestion to the OS. Mostly followed, depending on the device models hardware capabilities. 256 frames is supported on all current iOS devices. Smaller numbers may work on only some newer iOS device models. But iOS devices are free to use different buffer sizes (thus durations) for each audio unit callback. And sometimes does (due to power management, audio route changes, hardware start/stop issues, and etc.)
2) The interval between the starts of Audio Unit buffer callbacks is extremely consistent. Highly variable latency issues are usually the result of the code inside the callbacks taking too long. Did you follow all the audio context real-time rules? (no long operations, no Swift, no Objective C messaging, no locks, no memory management, no file reads or writes, no UI calls, and etc. ?)

Related

Google Sheets: How can I FILTER a range based on a value in the previous row?

I'm working with a golf data set and I'm looking for a way to filter holes based on the result of a previous hole. In the end, I want this range to be able to get the average score of the golfer following a bogey or worse.
I've made a few attempts with FILTER(), OFFSET(), and even INDIRECT(), but I can't figure out how to properly use values from a different row as the condition for my filter.
=FILTER(A2:D10, OFFSET(D2:D10, -1, 0) >= 1, ROW(D2:D10) <> 2) (errors with "FILTER has mismatched range sizes.")
=INDIRECT("D"&FILTER(ROW(A2:D10)+1, D2:D10 >= 1, ROW(D2:D10) <> 2)) (only returns the first value)
Sample Data:
A B C D
-----------------------------
1 | Hole Par Score ScoreDiff
2 | 1 4 5 1
3 | 2 4 4 0
4 | 3 4 3 -1
5 | 4 5 6 1
6 | 5 3 3 0
7 | 6 5 6 1
8 | 7 3 4 1
9 | 8 4 5 1
10 | 9 4 4 0
Desired outcome: only the holes directly following a bogey or worse (where ScoreDiff >= 1)
A B C D
-----------------------------
1 | 2 4 4 0
2 | 5 3 3 0
3 | 7 3 4 1
4 | 8 4 5 1
5 | 9 4 4 0
Simpler option:
=FILTER(A3:D11,D2:D10>=1)
try:
=FILTER(A2:D10, {""; D2:D9} >= 1, ROW(D2:D10) <> 2)

when using the default 'randomForest' algorithm for classification, why doesn't the number of terminal nodes match the number of cases?

According to https://cran.r-project.org/web/packages/randomForest/randomForest.pdf, classification trees are fully grown, meaning node size = 1.
However, if trees are really grown to a maximum, then shouldn't each terminal node contain a single case (data point, species, etc)?
If I run:
library(randomForest)
data(iris) #150 cases
set.seed(352)
rf <- randomForest(Species ~ ., iris)
hist(treesize(rf),main ="number of nodes")
I can see that most "fully grown" trees only have about 10 nodes, meaning node size can't be equal to 1...Right?
for example, (-1) below represents a terminal node for the 134th tree in the forest. Only 8 terminal nodes!?
> getTree(rf,134)
left daughter right daughter split var split point status prediction
1 2 3 3 2.50 1 0
2 0 0 0 0.00 -1 1
3 4 5 4 1.75 1 0
4 6 7 3 4.95 1 0
5 8 9 3 4.85 1 0
6 10 11 4 1.60 1 0
7 12 13 1 6.50 1 0
8 14 15 1 5.95 1 0
9 0 0 0 0.00 -1 3
10 0 0 0 0.00 -1 2
11 0 0 0 0.00 -1 3
12 0 0 0 0.00 -1 3
13 0 0 0 0.00 -1 2
14 0 0 0 0.00 -1 2
15 0 0 0 0.00 -1 3
I would be greatful if someone can explain
"Fully grown" -> "Nothing left to split". A (node of a-) decision tree is fully grown, if all data records assigned to it hold/make the same prediction.
In the iris dataset case, once you reach a node with 50 setosa data records in it, it doesn't make sense to split it into two child nodes with 25 and 25 setosas each.

Python3 print formatting

I want to format the output from print function.
def main():
print('1 2 3 4 5'*7)
# Write code here
main()
Required Output:
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
Obtained Output:
1 2 3 4 51 2 3 4 51 2 3 4 51 2 3 4 51 2 3 4 51 2 3 4 51 2 3 4 5
How do I make print function in Python3 to perform this job?
You can set the separator to be a linebreak.
print(*7*('1 2 3 4 5',), sep='\n')
Equivalently, you can add the linebreak at the end of the string and remove the end linebreak from print.
print(7*'1 2 3 4 5\n', end='')
Try this:
print('1 2 3 4 5\n'*7)

ERROR while implementing Cox PH model for recurrent event survival analysis using counting process

I have been trying to run Cox PH model on a sample data set of 10k customers (randomly taken from 32 million customer base) for predicting probability of survival in time t (which is month in my case). I am using recurrent event survival analysis using counting process for e-commerce. For this...
1. Observation starting point: right after a customer makes first purchase
2. Start/Stop times: Months of two consecutive purchases (as in the data)
I have a few independent variables as in the sample data below:
id start stop status tenure orders revenue Quantity
A 0 20 0 0 1 $89.0 1
B 0 17 0 0 1 $556.0 2
C 0 17 0 0 1 $900.0 2
D 32 33 0 1679 9 $357.8 9
D 26 32 1 1497 7 $326.8 7
D 23 26 1 1405 4 $142.9 4
D 17 23 1 1219 3 $63.9 3
D 9 17 1 978 2 $50.0 2
D 0 9 1 694 1 $35.0 1
E 0 15 0 28 2 $156.0 2
F 0 15 0 0 1 $348.0 1
F 12 14 0 375 2 $216.8 3
F 0 12 1 0 1 $67.8 2
G 9 15 0 277 2 $419.0 2
G 0 9 1 0 1 $359.0 1
While running cox PH using the following code:
fit10=coxph(Surv(start,stop,status)~orders+tenure+Quantity+revenue,data=test)
I keep getting the following error:
Warning: X matrix deemed to be singular; variable 1 2 3 4
I tried searching for the same error online but the answers I found said this could be because of interacting independent variables, whereas my variables are individual and continuous.

why the result of method mostSimilarItems in mahout is not order by the weight?

I have the following codes:
ItemSimilarity itemSimilarity = new UncenteredCosineSimilarity(dataModel);
recommender = new GenericItemBasedRecommender(dataModel,itemSimilarity);
List<RecommendedItem> items = recommender.mostSimilarItems(10, 5);
my datamodel is like this:
uid itemid socre
userid itemid score
1 6 5
1 10 3
1 11 5
1 12 4
1 13 5
2 2 3
2 6 5
2 10 3
2 12 5
when I run the code above,the result is just like this:
13
6
11
2
12
I debug the code,and find that the List items = recommender.mostSimilarItems(10, 5); return the items has the same score,that is one!
so,I have a problem.in my opinion,I think the mostsimilaritem should consider the item co-occurrence matrix:
2 6 10 11 12 13
2 0 1 1 0 1 0
6 1 0 2 1 2 1
10 1 2 0 1 2 1
11 0 1 1 0 1 1
12 1 2 2 1 0 1
13 0 1 1 1 1 0
in the matrix above ,the item 12's most similar should be [6,12,11,13,2],because the item 1 and item 12 is more similar than the other items,isn't it?
now,anyone who can explain this for me?thanks!
In your matrix you have much more data than in your input. In particular you seem to be imputing 0 values that are not in the data. That is why you are likely getting answers different from what you expect.
Mahout expects your IDs to be contiguous Integers starting from 0. This is true of your row and column ids. Your matrix looks like it has missing ids. Just having Integers is not enough.
Could this be the problem? Not sure what Mahout would do with the input above.
I always keep a dictionary to map Mahout IDs to/from my own.

Resources