Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to smoothly interpolate between two distributions? #733

Unanswered
imxtx asked this question in Q&A
Discussion options

Hi there, I'm using the ot.unbalanced.barycenter_unbalanced function to interpolate between two curves. However, I found some unsmooth interpolants between the source and the target (marked by squares in the figure below).

image

I want to transform the source curve to the target curve smoothly without producing these sawteeth. How should I achieve this?

Here is my code:

# Positions
x = np.arange(len(src)).reshape(-1, 1) # shape: [F, 1]
n_bins = len(src)
# Cost matrix: squared Euclidean distance
C = ot.utils.dist(x, x, metric='sqeuclidean')
# Input distributions
a = src.copy() # shape: (100,)
b = tgt.copy() # shape: (100,)
# Stack them into a matrix: [n_bins, n_distributions]
distributions = np.stack([a, b], axis=1) # shape: [F, 2]
# Weights for interpolation (e.g. t=0.3 → 30% a + 70% b)
t_values = np.linspace(0.1, 0.9, 5)
colors = ['g', 'c', 'm', 'y', 'k']
# Plot original
plt.figure(figsize=(10, 6))
plt.plot(x, 10 * np.log10(a), 'b', label='Source distribution')
plt.plot(x, 10 * np.log10(b), 'r', label='Target distribution')
for t, color in zip(t_values, colors):
 weights = np.array([1 - t, t])
 # Compute unbalanced barycenter
 barycenter = ot.unbalanced.barycenter_unbalanced(
 distributions, C, reg=1e-1, reg_m=10, weights=weights
 ) # shape: [F,]
 plt.plot(x, 10 * np.log10(barycenter), color=color, label=f"t={t:.1f}")
plt.title("Unbalanced OT Barycentric Interpolation (POT)")
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /