How to find the optimal number k of components?

pc = nlpca(data,k)

To find the optimal number of components in NLPCA is the same difficult problem as in classical linear PCA,

there are some strategies, but often it depends on your individual problem.

a) test several numbers k

When you use NLPCA in recommended hierarchical mode, the components will be ranked/ordered as in classical linear PCA. You could set k=10 (or maybe better only 5) nonlinear components and later check the results of the first, first two, first three,... components, to find the optimal number for your problem.

However, when you use NLPCA in the faster classical symmetric mode, even though the nonlinear component-subspace is the same, the components have no order, hence you would need to set the exact number you need.

b) use missing data validation for estimating the best k

Missing data estimation is used to estimate the optimal complexity parameter (weight-decay).

This approach can also be used to estimate the optimal number k of components: instead of testing several weight-decay values, you can test several k values.