Loss function (and encoding?) for anglesEncoding Angle Data for Neural NetworkWhat is a correct loss for a model predicting angles from images?Weighted loss function for non-random sampleBad performance with ReLU activation function on MNIST data setCross Entropy Loss for One Hot EncodingTensorflow 2.0/Keras - loss function with multiple inputsRegarding loss function
Bit floating sequence
More than 3 domains hosted on IP
Filling attribute tables with values from the same attribute table
Does the word voltage exist in academic engineering?
I won a car in a poker game. How is that taxed in Canada?
Why is Sojdlg123aljg a common password?
What geological processes could form the Crystal Desert on the planet Thra in the Dark Crystal?
Was Rosie the Riveter sourced from a Michelangelo painting?
Examples where "thin + thin = nice and thick"
Sinning and G-d's will, what's wrong with this logic?
Professor refuses to write a recommendation letter to students who haven't written a research paper with him
Do aarakocra have arms as well as wings?
Book/story which features a mental link to a prophet
If every star in the universe except the Sun were destroyed, would we die?
Is mountain bike good for long distances?
Owner keeps cutting corners and poaching workers for his other company
antimatter annihilation in stars
Is Sanskrit really the mother of all languages?
Friend is very nit picky about side comments I don't intend to be taken too seriously
What can we do about our 9-month-old putting fingers down his throat?
Why can't some airports handle heavy aircraft while others do it easily (same runway length)?
How can I know what hashing algorithm SQL Server used to decrypt the encrypted data when using the function DECRYPTBYPASSPHRASE?
Why did Tony's Arc Reactor do this?
First Number to Contain Each Letter
Loss function (and encoding?) for angles
Encoding Angle Data for Neural NetworkWhat is a correct loss for a model predicting angles from images?Weighted loss function for non-random sampleBad performance with ReLU activation function on MNIST data setCross Entropy Loss for One Hot EncodingTensorflow 2.0/Keras - loss function with multiple inputsRegarding loss function
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
I'm training a network to predict the angle of arrival of a signal. Labels are single values in the [-180, 180) interval.
I'm seeing a discontinuity in predictions around ±180 degrees, which makes sense as losses around that gap are incorrectly calculated by root mean square error.
I'm looking for a loss function that works in a modular way. A difference between 175 and -175 degrees should be calculated as 10 (instead of 350), if such thing exists.
It's my understanding that such a function introduces a discontinuity and thus may not be a valid approach. I'm looking for some guidance about how to deal with these kind of circular variables like angles, hour of the day, day of the week...
This has been addressed in the question "Encoding Angle Data for Neural Network", and I feel preserving linearity in angle variables is important (my input is also several angles), and I'm not getting good results with the sin/cos encoding approach proposed in that question. The problem is also discussed here: What is a correct loss for a model predicting angles from images?.
Here is what I'm doing currently, which works quite well with angles (-180, 180).
def metric_stddev_diff(y_true, y_pred):
return tf.keras.backend.std(y_true - y_pred)
def model_create():
model = tf.keras.Sequential([
tf.keras.layers.Dense(128, activation='sigmoid', dtype='float64'),
tf.keras.layers.Dense(64, activation='linear', dtype='float64'),
tf.keras.layers.Dense(1, activation='linear', dtype='float64'),
])
model.compile(optimizer='adam', # 'rmsprop' 'adam',
loss='mean_absolute_error', # 'mean_absolute_error' 'mean_squared_error' 'sparse_categorical_crossentropy'
metrics=['mean_absolute_error', metric_stddev_diff])
return model
loss-functions tensorflow keras circular-statistics
New contributor
jjmontes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
I'm training a network to predict the angle of arrival of a signal. Labels are single values in the [-180, 180) interval.
I'm seeing a discontinuity in predictions around ±180 degrees, which makes sense as losses around that gap are incorrectly calculated by root mean square error.
I'm looking for a loss function that works in a modular way. A difference between 175 and -175 degrees should be calculated as 10 (instead of 350), if such thing exists.
It's my understanding that such a function introduces a discontinuity and thus may not be a valid approach. I'm looking for some guidance about how to deal with these kind of circular variables like angles, hour of the day, day of the week...
This has been addressed in the question "Encoding Angle Data for Neural Network", and I feel preserving linearity in angle variables is important (my input is also several angles), and I'm not getting good results with the sin/cos encoding approach proposed in that question. The problem is also discussed here: What is a correct loss for a model predicting angles from images?.
Here is what I'm doing currently, which works quite well with angles (-180, 180).
def metric_stddev_diff(y_true, y_pred):
return tf.keras.backend.std(y_true - y_pred)
def model_create():
model = tf.keras.Sequential([
tf.keras.layers.Dense(128, activation='sigmoid', dtype='float64'),
tf.keras.layers.Dense(64, activation='linear', dtype='float64'),
tf.keras.layers.Dense(1, activation='linear', dtype='float64'),
])
model.compile(optimizer='adam', # 'rmsprop' 'adam',
loss='mean_absolute_error', # 'mean_absolute_error' 'mean_squared_error' 'sparse_categorical_crossentropy'
metrics=['mean_absolute_error', metric_stddev_diff])
return model
loss-functions tensorflow keras circular-statistics
New contributor
jjmontes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
$begingroup$
How did you try to compare after you map to $sin theta, cos theta$?
$endgroup$
– Cowboy Trader
6 hours ago
$begingroup$
I kept using "mean absolute difference" which was working nicely in the angles case. I suspect that's wrong... I don't really know how to interpret this metric in the $sin theta, cos theta$ case and I guess the loss function is not valid.
$endgroup$
– jjmontes
4 hours ago
add a comment |
$begingroup$
I'm training a network to predict the angle of arrival of a signal. Labels are single values in the [-180, 180) interval.
I'm seeing a discontinuity in predictions around ±180 degrees, which makes sense as losses around that gap are incorrectly calculated by root mean square error.
I'm looking for a loss function that works in a modular way. A difference between 175 and -175 degrees should be calculated as 10 (instead of 350), if such thing exists.
It's my understanding that such a function introduces a discontinuity and thus may not be a valid approach. I'm looking for some guidance about how to deal with these kind of circular variables like angles, hour of the day, day of the week...
This has been addressed in the question "Encoding Angle Data for Neural Network", and I feel preserving linearity in angle variables is important (my input is also several angles), and I'm not getting good results with the sin/cos encoding approach proposed in that question. The problem is also discussed here: What is a correct loss for a model predicting angles from images?.
Here is what I'm doing currently, which works quite well with angles (-180, 180).
def metric_stddev_diff(y_true, y_pred):
return tf.keras.backend.std(y_true - y_pred)
def model_create():
model = tf.keras.Sequential([
tf.keras.layers.Dense(128, activation='sigmoid', dtype='float64'),
tf.keras.layers.Dense(64, activation='linear', dtype='float64'),
tf.keras.layers.Dense(1, activation='linear', dtype='float64'),
])
model.compile(optimizer='adam', # 'rmsprop' 'adam',
loss='mean_absolute_error', # 'mean_absolute_error' 'mean_squared_error' 'sparse_categorical_crossentropy'
metrics=['mean_absolute_error', metric_stddev_diff])
return model
loss-functions tensorflow keras circular-statistics
New contributor
jjmontes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
I'm training a network to predict the angle of arrival of a signal. Labels are single values in the [-180, 180) interval.
I'm seeing a discontinuity in predictions around ±180 degrees, which makes sense as losses around that gap are incorrectly calculated by root mean square error.
I'm looking for a loss function that works in a modular way. A difference between 175 and -175 degrees should be calculated as 10 (instead of 350), if such thing exists.
It's my understanding that such a function introduces a discontinuity and thus may not be a valid approach. I'm looking for some guidance about how to deal with these kind of circular variables like angles, hour of the day, day of the week...
This has been addressed in the question "Encoding Angle Data for Neural Network", and I feel preserving linearity in angle variables is important (my input is also several angles), and I'm not getting good results with the sin/cos encoding approach proposed in that question. The problem is also discussed here: What is a correct loss for a model predicting angles from images?.
Here is what I'm doing currently, which works quite well with angles (-180, 180).
def metric_stddev_diff(y_true, y_pred):
return tf.keras.backend.std(y_true - y_pred)
def model_create():
model = tf.keras.Sequential([
tf.keras.layers.Dense(128, activation='sigmoid', dtype='float64'),
tf.keras.layers.Dense(64, activation='linear', dtype='float64'),
tf.keras.layers.Dense(1, activation='linear', dtype='float64'),
])
model.compile(optimizer='adam', # 'rmsprop' 'adam',
loss='mean_absolute_error', # 'mean_absolute_error' 'mean_squared_error' 'sparse_categorical_crossentropy'
metrics=['mean_absolute_error', metric_stddev_diff])
return model
loss-functions tensorflow keras circular-statistics
loss-functions tensorflow keras circular-statistics
New contributor
jjmontes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
jjmontes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 4 hours ago
jjmontes
New contributor
jjmontes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 8 hours ago
jjmontesjjmontes
1164 bronze badges
1164 bronze badges
New contributor
jjmontes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
jjmontes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$begingroup$
How did you try to compare after you map to $sin theta, cos theta$?
$endgroup$
– Cowboy Trader
6 hours ago
$begingroup$
I kept using "mean absolute difference" which was working nicely in the angles case. I suspect that's wrong... I don't really know how to interpret this metric in the $sin theta, cos theta$ case and I guess the loss function is not valid.
$endgroup$
– jjmontes
4 hours ago
add a comment |
$begingroup$
How did you try to compare after you map to $sin theta, cos theta$?
$endgroup$
– Cowboy Trader
6 hours ago
$begingroup$
I kept using "mean absolute difference" which was working nicely in the angles case. I suspect that's wrong... I don't really know how to interpret this metric in the $sin theta, cos theta$ case and I guess the loss function is not valid.
$endgroup$
– jjmontes
4 hours ago
$begingroup$
How did you try to compare after you map to $sin theta, cos theta$?
$endgroup$
– Cowboy Trader
6 hours ago
$begingroup$
How did you try to compare after you map to $sin theta, cos theta$?
$endgroup$
– Cowboy Trader
6 hours ago
$begingroup$
I kept using "mean absolute difference" which was working nicely in the angles case. I suspect that's wrong... I don't really know how to interpret this metric in the $sin theta, cos theta$ case and I guess the loss function is not valid.
$endgroup$
– jjmontes
4 hours ago
$begingroup$
I kept using "mean absolute difference" which was working nicely in the angles case. I suspect that's wrong... I don't really know how to interpret this metric in the $sin theta, cos theta$ case and I guess the loss function is not valid.
$endgroup$
– jjmontes
4 hours ago
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
Almost any loss function that is symmetric and differentiable at $0$ is locally quadratic. Thus, you don't have to be too fussy when searching for a good loss function when you need symmetry and differentiability.
Notice that with nearby angles $phi$ and $theta,$ the Taylor series expansion of the cosine gives
$$mathcalL(phi,theta)=2(1 - cos(phi-theta)) = (phi-theta)^2 + O((phi-theta)^4)$$
is locally quadratic at $phi-theta=0$ (and all integral multiples of $2pi$) through third order. Moreover, this function of $phi$ and $theta$ isn't badly behaved: it's defined for all angles, is differentiable everywhere, and--most importantly--respects the modular nature of angle comparison. Thus $mathcalL$ is a natural and simple angular version of a quadratic loss. This would be a good place to start your analysis.
If you need more flexibility, consider defining your loss as a function of $sqrt2(1-cos(phi-theta)):$ clearly this is a circular analog of the absolute difference.
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "65"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
jjmontes is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstats.stackexchange.com%2fquestions%2f425234%2floss-function-and-encoding-for-angles%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Almost any loss function that is symmetric and differentiable at $0$ is locally quadratic. Thus, you don't have to be too fussy when searching for a good loss function when you need symmetry and differentiability.
Notice that with nearby angles $phi$ and $theta,$ the Taylor series expansion of the cosine gives
$$mathcalL(phi,theta)=2(1 - cos(phi-theta)) = (phi-theta)^2 + O((phi-theta)^4)$$
is locally quadratic at $phi-theta=0$ (and all integral multiples of $2pi$) through third order. Moreover, this function of $phi$ and $theta$ isn't badly behaved: it's defined for all angles, is differentiable everywhere, and--most importantly--respects the modular nature of angle comparison. Thus $mathcalL$ is a natural and simple angular version of a quadratic loss. This would be a good place to start your analysis.
If you need more flexibility, consider defining your loss as a function of $sqrt2(1-cos(phi-theta)):$ clearly this is a circular analog of the absolute difference.
$endgroup$
add a comment |
$begingroup$
Almost any loss function that is symmetric and differentiable at $0$ is locally quadratic. Thus, you don't have to be too fussy when searching for a good loss function when you need symmetry and differentiability.
Notice that with nearby angles $phi$ and $theta,$ the Taylor series expansion of the cosine gives
$$mathcalL(phi,theta)=2(1 - cos(phi-theta)) = (phi-theta)^2 + O((phi-theta)^4)$$
is locally quadratic at $phi-theta=0$ (and all integral multiples of $2pi$) through third order. Moreover, this function of $phi$ and $theta$ isn't badly behaved: it's defined for all angles, is differentiable everywhere, and--most importantly--respects the modular nature of angle comparison. Thus $mathcalL$ is a natural and simple angular version of a quadratic loss. This would be a good place to start your analysis.
If you need more flexibility, consider defining your loss as a function of $sqrt2(1-cos(phi-theta)):$ clearly this is a circular analog of the absolute difference.
$endgroup$
add a comment |
$begingroup$
Almost any loss function that is symmetric and differentiable at $0$ is locally quadratic. Thus, you don't have to be too fussy when searching for a good loss function when you need symmetry and differentiability.
Notice that with nearby angles $phi$ and $theta,$ the Taylor series expansion of the cosine gives
$$mathcalL(phi,theta)=2(1 - cos(phi-theta)) = (phi-theta)^2 + O((phi-theta)^4)$$
is locally quadratic at $phi-theta=0$ (and all integral multiples of $2pi$) through third order. Moreover, this function of $phi$ and $theta$ isn't badly behaved: it's defined for all angles, is differentiable everywhere, and--most importantly--respects the modular nature of angle comparison. Thus $mathcalL$ is a natural and simple angular version of a quadratic loss. This would be a good place to start your analysis.
If you need more flexibility, consider defining your loss as a function of $sqrt2(1-cos(phi-theta)):$ clearly this is a circular analog of the absolute difference.
$endgroup$
Almost any loss function that is symmetric and differentiable at $0$ is locally quadratic. Thus, you don't have to be too fussy when searching for a good loss function when you need symmetry and differentiability.
Notice that with nearby angles $phi$ and $theta,$ the Taylor series expansion of the cosine gives
$$mathcalL(phi,theta)=2(1 - cos(phi-theta)) = (phi-theta)^2 + O((phi-theta)^4)$$
is locally quadratic at $phi-theta=0$ (and all integral multiples of $2pi$) through third order. Moreover, this function of $phi$ and $theta$ isn't badly behaved: it's defined for all angles, is differentiable everywhere, and--most importantly--respects the modular nature of angle comparison. Thus $mathcalL$ is a natural and simple angular version of a quadratic loss. This would be a good place to start your analysis.
If you need more flexibility, consider defining your loss as a function of $sqrt2(1-cos(phi-theta)):$ clearly this is a circular analog of the absolute difference.
answered 2 hours ago
whuber♦whuber
217k34 gold badges477 silver badges870 bronze badges
217k34 gold badges477 silver badges870 bronze badges
add a comment |
add a comment |
jjmontes is a new contributor. Be nice, and check out our Code of Conduct.
jjmontes is a new contributor. Be nice, and check out our Code of Conduct.
jjmontes is a new contributor. Be nice, and check out our Code of Conduct.
jjmontes is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Cross Validated!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstats.stackexchange.com%2fquestions%2f425234%2floss-function-and-encoding-for-angles%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
How did you try to compare after you map to $sin theta, cos theta$?
$endgroup$
– Cowboy Trader
6 hours ago
$begingroup$
I kept using "mean absolute difference" which was working nicely in the angles case. I suspect that's wrong... I don't really know how to interpret this metric in the $sin theta, cos theta$ case and I guess the loss function is not valid.
$endgroup$
– jjmontes
4 hours ago